Python for Visualization Flashcards
Pandas function that converts column to datetime type and return a series object
dataframe[‘col’] = pandas.to_datetime(df[‘col’])
Library used to create charts
matplotlib
matplotlib module that provides a high-level interface that allows us to quickly create common data plots and perform common tweaks to them
pyplot
Code to import pyplot module
import matplotlib.pyplot as plt
pyplot functions to (1) create chart and (2) display
plt. plot(x_values, y_values, c=’color’, label=’label’)
plt. show()
For x and y values, matplotlib will accept any iterable object, like NumPy arrays and pandas.Series instances
pyplot function to customize behavior of x-axis ticks
plt.xticks()
pyplot function to modify x-axis labels
plt.xlabel()
accepts a string value, which gets set as the x-axis label
pyplot function to modify y-axis labels
plt.ylabel()
accepts a string value, which is set as the y-axis label
pyplot function to modify chart title
plt.title()
accepts a string value, which is set as the plot title
pyplot function to manually create a figure
A figure acts as a container for all plots and has methods for customizing the appearance and behavior for the plots within that container.
fig = plt.figure()
Method to add a subplot to an existing figure, which will return a new axes object that needs to be assigned to a variable
axes_obj = fig.add_subplot(nrows, ncols, plot_number)
Creating a figure with 2 plots, one above the other
ax1 = fig.add_subplot(2,1,1) ax2 = fig.add_subplot(2,1,2)
Parameter to adjust dimensions of the plotting area
figsize (use when calling plt.figure())
fig = plt.figure(figsize=(width, height))
Width & height are in inches
Method to add a title to axes object
axes. set_title
ax1. set_title(‘Chart Name’)
Built in type that represents an immutable sequence of numbers and is commonly used for looping a specific number of times in for loops
range(start, stop[, step])
Ex: for i in range(5)
Produces a sequence of integers starting at zero, and going up to (but not including) the argument’s value