Jump to content

Matplotlib: Difference between revisions

996 bytes added ,  12 December 2019
no edit summary
(Created page with "Matplotlib is used for making plots in Python")
 
No edit summary
Line 1: Line 1:
Matplotlib is used for making plots in Python
Matplotlib is used for making plots in Python
==Installation==
<pre>
pip install matplotlib
</pre>
==Usage==
Usually you import as follows
<syntaxhighlight lang="bash">
import matplotlib.pyplot as plt
</syntaxhighlight>
===Saving a plot===
<syntaxhighlight lang="python">
plt.savefig("my_figure.png", dpi=450)
</syntaxhighlight>
===Fonts===
[https://stackoverflow.com/questions/3899980/how-to-change-the-font-size-on-a-matplotlib-plot Reference]<br>
<syntaxhighlight lang="python">
SMALL_SIZE = 8
MEDIUM_SIZE = 10
BIGGER_SIZE = 12
plt.rc('font', size=SMALL_SIZE)          # controls default text sizes
plt.rc('axes', titlesize=SMALL_SIZE)    # fontsize of the axes title
plt.rc('axes', labelsize=MEDIUM_SIZE)    # fontsize of the x and y labels
plt.rc('xtick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE)    # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE)  # fontsize of the figure title
</syntaxhighlight>