Difference between revisions of "Matplotlib"

From wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
[[Category:Python]]
 
[[Category:Python]]
Using the pyplot functions only until now.
+
Using the [https://matplotlib.org/tutorials/introductory/pyplot.html#sphx-glr-tutorials-introductory-pyplot-py pyplot] functions only until now.
 
;import matplotlib.pyplot as plt
 
;import matplotlib.pyplot as plt
 
:Get the pyplot library. We assume this is done in all examples on this page.
 
:Get the pyplot library. We assume this is done in all examples on this page.
 +
;plt.figure(2)
 +
:Initialize a new figure. figure(1) is initialized by default.
 +
;plt.subplot(211)
 +
:Create 1st subplot in figure(1) (212 is the 2nd subplot in figure(1)
 +
:211 : Split the figure in 2, figure(1) subplot 1
 
;plt.plot(array)
 
;plt.plot(array)
 
:Create the graphical object from the values in the array. Show the graph if your environment (e.g. [https://jupyter.org/ jupyter]) supports it.
 
:Create the graphical object from the values in the array. Show the graph if your environment (e.g. [https://jupyter.org/ jupyter]) supports it.
 +
:When you do more plots without changing figure or subplot the result will be added to the current figure.
 +
;plt.show()
 +
:Show the current figure.
 +
  
 
Selfexplaning example code:
 
Selfexplaning example code:
Line 13: Line 22:
 
plt.ylabel('Set the y label')
 
plt.ylabel('Set the y label')
 
plt.savefig('plot.png')
 
plt.savefig('plot.png')
 +
plt.show()
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Show the image:
+
Show an image:
 
<syntaxhighlight lang=bash>
 
<syntaxhighlight lang=bash>
 
firefox plot.png
 
firefox plot.png

Revision as of 23:52, 16 December 2018

Using the pyplot functions only until now.

import matplotlib.pyplot as plt
Get the pyplot library. We assume this is done in all examples on this page.
plt.figure(2)
Initialize a new figure. figure(1) is initialized by default.
plt.subplot(211)
Create 1st subplot in figure(1) (212 is the 2nd subplot in figure(1)
211 : Split the figure in 2, figure(1) subplot 1
plt.plot(array)
Create the graphical object from the values in the array. Show the graph if your environment (e.g. jupyter) supports it.
When you do more plots without changing figure or subplot the result will be added to the current figure.
plt.show()
Show the current figure.


Selfexplaning example code:

plt.plot(array)
plt.suptitle('Set the graph tilte')
plt.xlabel('Set the x label')
plt.ylabel('Set the y label')
plt.savefig('plot.png')
plt.show()

Show an image:

firefox plot.png
eog plot.png
shotwell plot.png