I want to plot two y-axis and one x-axis, for only one picture in one graph window i know how to do, but how to change this code to draw 4 pictures in one graph window?
ax1 = axes()
ax2 = ax1.twinx()
x = np.arange(100)
y1 = np.random.rand(100)
y2 = np.random.rand(100)
ax1.plot(x,y1,'-r')
ax1.set_ylim(-1,1)
ax2.fill_between(x,0,y2,color='b',alpha=0.5)
ax2.set_ylim(0,2)
ax1.set_ylabel('Red')
ax2.set_ylabel('Blue')
Here is a possible way to go about it. I have only twined one axis, but indeed all axis can be treated similarly.
import matplotlib.pyplot as plt
import numpy as np
fig, axarr = plt.subplots(nrows=2, ncols=2)
axTx = axarr[0, 0].twinx()
x = np.logspace(-1, 1, 100)
axarr[0, 0].plot(x, x, linewidth=2, color='xkcd:azure')
axTx.plot(x, 1 / x, linewidth=2, color='xkcd:avocado')
axarr[0, 0].tick_params(axis='y', labelcolor='xkcd:azure')
axTx.tick_params(axis='y', labelcolor='xkcd:avocado')
fig.tight_layout()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.