1

have two questions maybe someone can help me. I want to plot a stereographic projection with contoruf and want to color the higher parts in the Z direction in Matplotlib. For that i have two questions.

  1. I’m plotting with contourf before im using meshgrid and griddata, the the other edges are not smooth how can i smooth them? enter image description herei

  2. I want to have a log scale in Z how can i do that, i tried to use ticker.LogLocator but then i got just some parts colored.

Here my code:

# craation of a 2D grid
xi = np.linspace(min(X), max(X))
yi = np.linspace(min(Y), max(Y))

X1, Y1 = np.meshgrid(xi, yi)

##### interpolation
Z1 = griddata(X, Y, Z,xi,yi)

plt.contourf(X1,Y1,Z1,50,cmap=plt.cm.rainbow,vmax=abs(Z1).max(),
             locator=ticker.LogLocator)

plt.colorbar()

plt.xlim(-1,1)
plt.ylim(-1,1)

plt.show()
plt.set_zscale('log')
plt.set_xlabel('X')
plt.set_ylabel('Y')

plt.show()
4

1 回答 1

0

Answering the first question:

You can smooth the contour values doing:

zmin = Z1.min()
zmax=Z1.max()
levels=linspace(zmin, zmax, 400)

and then pass levels as an argument to plt.contourf().

To smooth the outer edges you have to use more values in your 2-D grid, which can be achieved passing the number of values you want when using linspace():

nx = 1000
ny = 1000
xi = np.linspace(min(X), max(X), nx)
yi = np.linspace(min(Y), max(Y), ny)
于 2014-06-19T10:40:11.703 回答