Tuesday, February 10, 2015

[Python] Plot

# Set the colorbar

(1)
plt.imshow(data, vmin=0, vmax=10, cmap='jet', aspect='auto')
(2)
plt.pcolor(X, Y, v, cmap=cm)
plt.clim(-4,4)
plt.show()

(3) Change the range of a colormap for a certain values
import matplotlib.colors as colors
(a)
cmap = cm.get_cmap('jet', 20)
cvals = cmap(arange(5, 20, 1))
ncmap = colors.ListerdColormap(mcolors)
(b)
mcolors = plt.cm.jet(linspace(0.3, 1, 256))
ncmap = colors.ListedColormap(mcolors)

(3)Remove the top and bottom axis
 def simpleaxis(ax):
  ax.spines['top'].set_visible(False) 
  ax.spines['right'].set_visible(False) 
  ax.get_xaxis().tick_bottom()
  ax.get_yaxis().tick_left()

(4) Draw the x=y line
plot([xmin, xmax],[ymin, ymax])


No comments:

Post a Comment