Pregunta

in plotting the data some times there are a few very large (or very small) numbers which, if not taken care of, will affect the contour in a bad way. a solution is to take out the 10% highest and lowest data out of the contour color grading and considering them as less than and more than. the following figure shows the idea: enter image description here

the two arrow shapes on the top and the bottom of the bar support this idea. any value above 14 will be shown in white and any value below -2 will be shown in black color. how is it possible in matplotlib? How can I define: - to put the 5% of highest values and 5% of lowest values in two categories shown in the triangular parts in both ends of the bar? (Should I define it the contour operation or are there other ways?) - what if I want to give certain values instead of the percentage? for instance, ask to put any value above 14 on the white triangule and any value below -2 as black areas?

Thank you so much for your help.

¿Fue útil?

Solución

Taken from http://matplotlib.org/examples/api/colorbar_only.html. You can play with it and you will see if it could solve your problem.

import matplotlib.pyplot as plt
from matplotlib import mpl
import numpy as np

x = np.linspace(-1,1,100)
X,Y = np.meshgrid(x,x)
Z = np.exp(-X**2-Y**2)

vmin = 0.3 #Lower value
vmax = 0.9 #Upper value

bounds = np.linspace(vmin,vmax,4)

cmap = mpl.colors.ListedColormap([(0,0,0),(0.5,0.5,0.5),(0,1,0),(1,1,1)])
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)

plt.imshow(Z,cmap=cmap,interpolation='nearest',vmin=vmin,vmax=vmax)

ax = plt.colorbar().ax
cb = mpl.colorbar.ColorbarBase(ax, norm=norm,
                               extend='both',
                               cmap=cmap)
cmap.set_over([0,0,1])
cmap.set_under([1,0,0])

plt.show()

enter image description here

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top