0% found this document useful (0 votes)
130 views2 pages

Python Data Visualization Guide

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
130 views2 pages

Python Data Visualization Guide

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

15.

003 Software Tools — Data Science Afshine Amidi & Shervine Amidi

Type Command Illustration


Study Guide: Data Visualization with Python
Box [Link](
x, y, params
Afshine Amidi and Shervine Amidi plot
)

August 21, 2020

[Link](
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 = [Link](...) where the meaning of parameters are summarized in the table below:
ax = sns...
# Legend Command Description Use case
[Link]()
[Link]() hue Color of a line / point / border ’red’
[Link]()
fill Color of an area ’red’
We note that the [Link]() 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 [Link](
x, y, params
plot Advanced features
)
r Text annotation – Plots can have text annotations with the following commands:

[Link]( Type Command Illustration


Line
x, y, params
plot
)
[Link](
Text x, y, s, color
)

Bar [Link](
x, y, params
chart
)
r Additional elements – We can add objects on the plot with the following commands:

Massachusetts Institute of Technology 1 [Link]


15.003 Software Tools — Data Science Afshine Amidi & Shervine Amidi

Type Command Illustration

[Link](
x, ymin, ymax, color,
linewidth, linestyle
)
Line

[Link](
y, xmin, xmax, color,
linewidth, linestyle
)
r Double axes – A plot can have more than one axis with the [Link]() command. It is
done as follows:

Python
[Link](
ax2 = [Link]()
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 = [Link](1, figsize=(width, height))

• Saving the figure itself:


Last touch Python
[Link](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
[Link](’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 [Link](’text’, x, y, fontsize)

This results in the following plot:

Massachusetts Institute of Technology 2 [Link]

You might also like