Skip to content Skip to sidebar Skip to footer

Set Matplotlib View To Be Normal To The X-y Plane In Python

This code found here is an example of a 3d surface plot: from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm from matplotlib.ticker import LinearLocator, FormatStrFor

Solution 1:

What you want is the ax.view_init function, with elev=90. See this answer

Edit:

after adding ax.view_init(azim=0, elev=90) to your script, I get this:

enter image description here


Solution 2:

You need pcolor for that:

import matplotlib.pyplot as plt
import numpy as np

dx, dy = 0.25, 0.25

y, x = np.mgrid[slice(-5, 5 + dy, dy),
                slice(-5, 5 + dx, dx)]
R = np.sqrt(x**2 + y**2)
z = np.sin(R)


z = z[:-1, :-1]
z_min, z_max = -np.abs(z).max(), np.abs(z).max()



plt.subplot()
plt.pcolor(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max)

plt.axis([x.min(), x.max(), y.min(), y.max()])
plt.colorbar()
plt.show()

enter image description here

Additional demos are here


Post a Comment for "Set Matplotlib View To Be Normal To The X-y Plane In Python"