python - How can I get matplotlib to make a colorbar with a color centered on 0? -
I am plotting to plot a wagger of some data, and in the extreme parts of the distribution the value is about 0 also very disappointed That's where my test plot looks like this:
In the blue "sea" waves are around 1 e-18 around one dimension, but because they fall around 0, they cross a line in the color palette.
How can I make a computation (), instead of being a conspiracy, there is a plot with zero color centered instead of zero?
I think you want something like this:
class set_cbar_zero (normal): "" "set_cbar_zero (midpoint = float) default: midpoint = 0. sets the center of any theater for normalized and desired value, which is set using midpoint." "Diff __int___ (self, vimine = none, vmx = none, midpoint = 0., clip = false): self. Mindpoint = midpoint normal .__ init __ (self, vmin, vmax, clip) def __call __ ( Self, original Return, numpy.ma.masked_array (numpy.interp (value, x, number, x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1] return numpy.ma.masked_array Y))
You can then normalize the colouration which should solve your problem, if I have understood it correctly
imported Import matplotlib.pylab as plt data = numpy.random.random ((30, 95)) plt.figure () plt.imshow (data, cm = "hot", ideal = set_ cbar_zero ()) plt.show ()
Comments
Post a Comment