Matplotlib contour map colorbar
Matplotlib doesn't know about your shift
variable. It is choosing to plot it that way because the changes you are trying to visualize are 10^(-6) of the background value.
You can force the colorbar to have tick marks at specific locations as they do in this pylab example using:
cbar = fig.colorbar(cax, ticks=[-1, 0, 1])
cbar.ax.set_yticklabels(['< -1', '0', '> 1']) # vertically oriented colorbar
However, doing so will make the scale very difficult to read.
Comments
-
jjv almost 2 years
I am plotting my data into a contour map. The computations work on the translated values, so I need to put it back to its original value. On the fourth line of the code, is the re-translation process. However, when I plotted it the colorbar shows the relative values, and just a note of the shift value at the top of the color bar. It is just weird that I checked the matrix values, and it contains the original values.
How can I show the colorbar, with the original values displayed?
fig=plt.figure() v=np.linspace(-180,180,25) x,y = np.meshgrid(v,v) z = np.add(z,-shift) z = z.reshape(25,25).T plt.contourf(x,y,z,25) fig.suptitle(AA(prefix)+' Input Data Contour Map') plt.xlabel('$\phi$ (deg)') plt.ylabel('$\psi$ (deg)') plt.xticks(np.arange(-180, 181, 30)) plt.yticks(np.arange(-180, 181, 30)) plt.colorbar()
UPDATE: I used set_ticklabels() for a temporary fix, where
labels
is a list of custom labels.But I am still looking for a better way to solve this problem.
plt.colorbar().set_ticklabels(labels)
-
jjv over 7 yearsjust wondering, before the plotting command, I checked the values in the
z
variable and it contains the original values, so it is more of a plotting problem in matplotlib.