Question

I've got a pcolormesh instance with an associated colorbar. Let's call my data points (X,Y) with associated values Z=f(X,Y). My data Z goes over a pretty large range and I'd like to focus in on a specific region in my (X,Y) space where this change in Z is much smaller. If I simply zoom into the plot or change the xlim/ylim values then my colorbar stays the same, and I'm not able to distinguish the small changes occuring in my region of interest (I want the colorbar to change to reflect the range of this smaller region).

Obviously, I could simply trim my data set of all points that existed outside my region of interest, and then plot that. But I'm wondering if there's a better way to do this without messing with the data.

Was it helpful?

Solution

You can set the keyword arguments vmin and vmax in pyplot.pcolormesh:

from numpy import linspace,meshgrid,pi,cos,sin
from matplotlib.pyplot import figure, show

x=linspace(0,100);y=linspace(0,100)
X,Y=meshgrid(x,y)
Z=cos(3*pi*X)+sin(6*pi*Y)

fig=figure()
ax=fig.add_subplot(111)
pc=ax.pcolormesh(X,Y,Z,vmin=0.3,vmax=0.6)
fig.colorbar(pc)
show()

This will make the values outside of your range saturate, so they'll all show up as the same colour. Happy matplotlibbing.

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