Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
100 views

Data Visualization With Python

This document provides a summary of data visualization techniques using Python. It outlines the general structure for plotting figures using matplotlib and seaborn, including commands for basic plots like scatter plots, line plots, and bar charts. It also describes advanced features like adding text annotations, additional elements, and double axes. The document concludes with instructions for saving figures by specifying dimensions and using the savefig command.

Uploaded by

Diego Rodríguez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views

Data Visualization With Python

This document provides a summary of data visualization techniques using Python. It outlines the general structure for plotting figures using matplotlib and seaborn, including commands for basic plots like scatter plots, line plots, and bar charts. It also describes advanced features like adding text annotations, additional elements, and double axes. The document concludes with instructions for saving figures by specifying dimensions and using the savefig command.

Uploaded by

Diego Rodríguez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

15.

003 Software Tools — Data Science Afshine Amidi & Shervine Amidi

Type Command Illustration


Study Guide: Data Visualization with Python
Box sns.boxplot(
x, y, params
Afshine Amidi and Shervine Amidi plot
)

August 21, 2020

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:

sns.lineplot( Type Command Illustration


Line
x, y, params
plot
)
ax.text(
Text x, y, s, color
)

Bar sns.barplot(
x, y, params
chart
)
r Additional elements – We can add objects on the plot with the following commands:

Massachusetts Institute of Technology 1 https://www.mit.edu/~amidi


15.003 Software Tools — Data Science Afshine Amidi & Shervine Amidi

Type Command Illustration

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))

• Saving the figure itself:


Last touch Python
f.savefig(fname)
r Legend – The title of legends can be customized to the plot with the commands summarized
below:

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)

This results in the following plot:

Massachusetts Institute of Technology 2 https://www.mit.edu/~amidi

You might also like