On 06/05/2015 03:57 PM, Joe Kington wrote:
This is great, but it has a slightly bothersome side effect on the colorbar ticks. In your original example, I changed the line 'data = "" * (data - 0.8)' to 'data = "" * (data - 0.85)', so that the numbers are now in between -8.5 and +1.5. As a result, when the colorbar is drawn, you get a tick at -8, as well as one at -9 (similarly at +1 and +2). Example attached. As in, the colorbar method seems intent on adding those tick marks at -9 and +2. The result is not aesthetically pleasing. In one of my real-data example, the minimum value of the data happened to be -4.003, and as a result there was a tick label at -4 and an overlapping tick label at -5. Why does this happen only when I specify 'norm' in imshow? How do I get matplotlib to not do that? Thanks, Sourish
--
Q: What if you strapped C4 to a boomerang? Could this be an effective weapon, or would it be as stupid as it sounds? A: Aerodynamics aside, I’m curious what tactical advantage you’re expecting to gain by having the high explosive fly back at you if it misses the target. |
import numpy as np import matplotlib.pyplot as plt from matplotlib.colors import Normalize class MidpointNormalize(Normalize): def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False): self.midpoint = midpoint Normalize.__init__(self, vmin, vmax, clip) def __call__(self, value, clip=None): # I'm ignoring masked values and all kinds of edge cases to make a # simple example... x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1] return np.ma.masked_array(np.interp(value, x, y)) data = np.random.random((10,10)) # generate data between -8.5 and +1.5 data = 10 * (data - 0.85) fig, ax = plt.subplots() norm = MidpointNormalize(midpoint=0.0) im = ax.imshow(data, norm=norm, cmap=plt.cm.seismic, interpolation='none') fig.colorbar(im) plt.show()
------------------------------------------------------------------------------
_______________________________________________ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users