简体   繁体   中英

Rotating a contourf plot 90 degrees with matplotlib

I am computing an analysis which looks at wave data for a given altitude above the surface of the Earth. While my altitude is an independent variable, I want to place it on the y-axis so it is easier to visualize. I don't want to actually flip the x and y data in the code, just rotate the graph.

plt3 = plt.subplot(gs[3, 0:3])
plt.title('Wave Graph')
plt.ylabel('wavelength [m]')
plt.xlabel('Altitude [km]')

WT = plt.contourf(Alt, Wavlgth, wave, 100, cmap=plt.cm.seismic, extend = 'both')
plt.xlim(xlim[:])
plt.ylim([np.min(period), np.max(period)])
ax = plt.gca().yaxis
plt.plot(time, coi, 'w')
plt3.fill_between(Alt, coi, np.max(coi), facecolor = 'white')

position2=fig.add_axes([.58, 0.03, 0.01, 0.2]) #Pos and size of colorbar
plt.colorbar(WT, cax=position2, orientation='vertical')

This creates a graph which looks like the following Imgur link . I tried rotating the array but nothing has seemed to solve it yet.

Since you didn't provide a Minimal, Complete, and Verifiable example I can't plot the result nor check your code.

Although if I understood correctly your question you need to switch Alt and Wavlgth and transpose wave:

WT = plt.contourf(Wavlgth, Alt, np.transpose(wave), 100, cmap=plt.cm.seismic, extend = 'both')

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM