Data Visualization With Python
Data Visualization With Python
003 Software Tools — Data Science Afshine Amidi & Shervine Amidi
sns.heatmap(
General structure Heatmap
data, params
)
r Overview – The general structure of the code that is used to plot figures is as follows:
Python
# Plot
f, ax = plt.subplots(...) where the meaning of parameters are summarized in the table below:
ax = sns...
# Legend Command Description Use case
plt.title()
plt.xlabel() hue Color of a line / point / border ’red’
plt.ylabel()
fill Color of an area ’red’
We note that the plt.subplots() command enables to specify the figure size. size Size of a line / point 4
r Basic plots – The main basic plots are summarized in the table below: linetype Shape of a line ’dashed’
alpha Transparency, between 0 and 1 0.3
Type Command Illustration
Scatter sns.scatterplot(
x, y, params
plot Advanced features
)
r Text annotation – Plots can have text annotations with the following commands:
Bar sns.barplot(
x, y, params
chart
)
r Additional elements – We can add objects on the plot with the following commands:
ax.axvline(
x, ymin, ymax, color,
linewidth, linestyle
)
Line
ax.axhline(
y, xmin, xmax, color,
linewidth, linestyle
)
r Double axes – A plot can have more than one axis with the plt.twinx() command. It is
done as follows:
Python
ax.axvspan(
ax2 = plt.twinx()
Rectangle xmin, xmax, ymin, ymax,
color, fill, alpha
) r Figure saving – There are two main steps to save a plot:
• Specifying the width and height of the plot when declaring the figure:
Python
f, ax = plt.subplots(1, figsize=(width, height))
Element Command
ax.set_title(’text’, loc, pad)
Title / subtitle of the plot
plt.suptitle(’text’, x, y, size, ha)
Title of the x / y axis ax.set_xlabel(’text’) / ax.set_ylabel(’text’)
Title of the size / color ax.get_legend_handles_labels()
Caption of the plot ax.text(’text’, x, y, fontsize)