Matplotlib do multiple vertical axes

The function of multi-axis in Matlab is very direct. The two-axis is plotyy, the three-axis is plotyyy, the four-axis is plot4y, and more should be multiplotyyy.

And matplotlib seems to be able to use figure.add_axes() to achieve, exploring...

Found a hidden function during the experiment

The jupyter notebook code is as follows:

%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()

t = np.arange(0.0, 1.0, 0.01)
s = np.sin (2 * np.pi * t)
c = np.cos(2 * np.pi * t)

ax1 = fig.add_axes([0, 0, 0.8, 0.5])
line1, = ax1.plot(t, s, color='blue', lw=2)
ax2 = fig.add_axes([0, 0, 0.8, 0.5])
line2, = ax2.plot(t, c, color='blue', lw=2)

plt.show()

After execution, a reminder pops up:

X:\anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py:106: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
  The effect of warnings.warn(message, mplDeprecation, stacklevel=1) 
graph is


Because the parameters are the same, the two figures are combined and displayed. If there is a difference in l,b,w,h in ax2 = fig.add_axes([0, 0, 0.8, 0.5]), the later definition directly covers the previous definition , or add the axes

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325515225&siteId=291194637