How to arrange two ylabels using Python Matplotlib.pyplot


The result is:


This page shows how to strictly align two ylabels.

Draw several plots in one figure in Python Matplotlib.pyplot


The result is:

Draw several plots in one figure in Python Matplotlib.pyplot

This page shows how to plot several waveforms (like waveform data taken by an oscilloscope) in one figure.
Using offsets for each waveform, we can automatically plot using python and matplotlib.pyplot according to following code.

Draw two legends in one figure using Python & Matplotlib.pyplot

In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
In [2]:
plt.figure(figsize=(4,3))

l1, = plt.plot([0,1],[1,0],label="l1")
l2, = plt.plot([0,1],[1.1,0],label="l2")
l3, = plt.plot([0,1],[1.2,0],label="l3")
h1 = [l1, l2, l3]
l4, = plt.plot([0,1],[0,1],"--",label="l4")
l5, = plt.plot([0,1],[0,1.1],"--",label="l5")
h2 = [l4, l5]

lab1 = [ h.get_label() for h in h1]
lab2 = [ h.get_label() for h in h2]

leg1 = plt.legend(h1,lab1, loc=1)
leg2 = plt.legend(h2,lab2, loc=4)

plt.gca().add_artist(leg1) # 最後の legend しか自動認識してくれない
plt.show()

One ylabel for two subplots using Python Matplotlib.pyplot


The result is:

One ylabel for two subplots using Python Matplotlib.pyplot

This page shows how to write one label on two subplots using python and matplotlib.pyplot. By set label_coords of the ylabel, you can move the position of the ylabel.

Write text annotation on image using Python Matplotlib.pyplot


The result is:

Write text annotation on image using Python Matplotlib.pyplot result

This page shows how to write texts and put plots on the image using Python and Matplotlib.pyplot. The Figures can be exported as vector image such as pdf and svg using plt.savefig. It is impossible if you use save function of PIL; Python Image Library.