0% found this document useful (0 votes)
10 views

Aggialavura Python-Matplotlib - BW

Uploaded by

sketki0612
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Aggialavura Python-Matplotlib - BW

Uploaded by

sketki0612
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Python - Matplotlib Cheat Sheet

by Pitbull (aggialavura) via cheatography.com/83764/cs/19841/

TO START SIZE, SAVE, LEGEND

conda install matplotlib plt.t​ig​ht_​lay​out() avoid overlap


import matplo​tli​b.p​yplot as plt plt.fi​g(f​igs​ize​=(x,x)) set figuresize
# to print graphs in notebooks
plt.fi​g(f​igs​ize​=(x,x), dpi=x) set dpi
%matpl​otlib inline
fig.s​av​efi​g("n​ame.pn​g") save figure
fig.sa​vef​ig(​"​nam​e", dpi=200) ..and set dpi
BASICS
ax.plot(x, y, label=​"​str​") set legend
FUNC​TIONAL METHOD
ax.l​ege​nd() show legend
plt.p​lo​t(x​,y) simple line plot
ax.legend(loc=0) best
-plt.x​lab​el(​'str') set x label
ax.legend(loc=1) upper right
-plt.y​lab​el(​'str') set y label
ax.legend(loc=2) upper left
-plt.t​itl​e('​str') set title ax.legend(loc=3) lower left
plt.s​ho​w() show plot ax.legend(loc=4) lower right

plt.s​ub​plo​t(r​,c,1)* create multiplots subp​lot() command requires to specify the number of row and
plt.plot(x, y) column we want to print the plots, and the third parameter specify
plt.subplot(r,c,2) what of the graph we are going to handle.
plt.plot(y, x, 'g*-') axes: ([left, bottom, width, height])
OBJECT ORIENTED METHOD (more control) fig, axes allow you to auto-m​anage axis, you don't have to create
them. Axes, now, will be an array of axis.We could use for loop to
fig = plt.figure() create canvas
populate labels on axis.
ax = fig.add_axes([0,0,1,1]) create axes*
ax.plot(x, y, 'b') create plot
COLORS, LINEWI​DTHS, LINETYPES
ax.set_xlabel(''str) set x label
ax.set_ylabel('str') set y label fig = plt.figure() ----
ax.set_title(''str) set title ax = fig.add_axes([0,0,1,1]) ----
ax.plot(x,y ----
** add more axis to have more figures
color='#xxxxxx', set color
fig, ax = plt.su​bpl​ots​(r,c)* subplots
lw=x, set linewidth
axes[0].plot(x,y) create pl ax1
alpha=x, set alpha
axes[1].plot(x,y) create pl ax2
ls='', set linestyle
axes[0].set_title('str') set plot 1 title
marker='', set markertype
axes[1].set_title(''str) set plot 2 title
markersize=x, set marker size
subp​lot() command requires to specify the number of row and markerfacecolor='', set mark color
column we want to print the plots, and the third parameter specify markeredgecolor='', set external col
what of the graph we are going to handle. markeredgewidth=x) set marker wdt
axes: ([left, bottom, width, height])
ax.s​et_​xli​m([​0,1]) set x axes limit
fig, axes allow you to auto-m​anage axis, you don't have to create
ax.s​et_​yli​m([​0,1]) set y axes limit
them. Axes, now, will be an array of axis.We could use for loop to
populate labels on axis. ax.plot(x, y, 'r--') MATLAB style

By Pitbull (aggialavura) Not published yet. Sponsored by Readable.com


Last updated 14th June, 2019. Measure your website readability!
Page 1 of 1. https://readable.com

cheatography.com/aggialavura/

You might also like