Question

I have a numpy arrays of temperature, wind speed, heat flux etc. Each of these arrays is assigned to its own subplot. The snow depth I would like to be plotted on the combined area of the subplots. As if the second y-axis is of one plot.

In the attached image is what I would like to create example plot. One can see the snow depth is on the secondary y-axis.

Was it helpful?

Solution

You can use twinx() to create a second y-axis that shares the same x-axis

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')

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top