|
From: Virgil S. <vs...@it...> - 2014-06-15 23:14:02
|
On 16-Jun-14 00:46, Raymond Smith wrote: > Hi Virgil, > > I did something very much like this recently by simply adding an axes > to my figure and using it to show a linspace of the data range off > which the line color was based. See > http://matplotlib.org/examples/color/colormaps_reference.html. > > Best, > Ray > > > On Sun, Jun 15, 2014 at 6:17 PM, Virgil Stokes <vs...@it... > <mailto:vs...@it...>> wrote: > > There are some rather nice and useful matplotlib examples for > colormaps that are shown at: > > http://nbviewer.ipython.org/github/dpsanders/matplotlib-examples/blob/master/colorline.ipynb > > In*Example 1. Sine wave colored by time (uses the defaults for > colorline)*, how can one add a colorbar? > > --V > > ------------------------------------------------------------------------------ > HPCC Systems Open Source Big Data Platform from LexisNexis Risk > Solutions > Find What Matters Most in Your Big Data with HPCC Systems > Open Source. Fast. Scalable. Simple. Ideal for Dirty Data. > Leverages Graph Analysis for Fast Processing & Easy Data Exploration > http://p.sf.net/sfu/hpccsystems > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > <mailto:Mat...@li...> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > Thanks for your response to my request, Ray. I had looked at this approach earlier; but, what I really need is something like is produced by the following code for the cax object: """Produce custom labelling for a colorbar. Original Script: Scott Sinclair Modification: V. Stokes """ import matplotlib.pyplot as plt import numpy as np import matplotlib.colors as col from matplotlib import cm from numpy.random import randn def register_cmap(): """ Purpose: define colormap using the from_List() method as a segmented list and register it. """ cmap_Name = 'reyegr' # my colormap name startcolor = '#00AF33' # truegreen midcolor = '#FFE600' # yolk (a medium dark yellow) endcolor = '#FF0033' # bright red cmap2 = col.LinearSegmentedColormap.from_list(cmap_Name, [startcolor,midcolor,endcolor]) cm.register_cmap(cmap=cmap2) return cm.get_cmap(cmap_Name) # my new cmap for 'reylgr' #----------------------------------------------------------------------------- my_cmap = register_cmap() ## Vertical colorbar-1 fig, ax = plt.subplots() data = np.clip(randn(250, 250), -1, 1) cax = ax.imshow(data, interpolation='nearest', cmap=my_cmap) ax.set_title('Gaussian noise with vertical colorbar') # Add colorbar, make sure to specify tick locations to match desired ticklabels cbar = fig.colorbar(cax, ticks=[-1, 0, 1]) cbar.ax.set_yticklabels(['<-1', '0', '> 1'])# vertically oriented colorbar ## Vertical colorbar-2 fig, ax = plt.subplots() data = np.clip(randn(50, 50), -1, 1) #cax = ax.imshow(data, interpolation='nearest', cmap=cm.coolwarm) cax = ax.imshow(data, interpolation='nearest', cmap=my_cmap) ax.set_title('Gaussian noise with vertical colorbar') # Add colorbar, make sure to specify tick locations to match desired ticklabels cbar = fig.colorbar(cax, ticks=[-1, 0, 1]) # Vertically oriented (by default) colorbar cbar.ax.set_yticklabels(['Low', 'Medium', 'High']) ## Horizontal colorbar fig, ax = plt.subplots() # cax = ax.imshow(data, interpolation='nearest', cmap=my_cmap) ax.set_title('Gaussian noise with horizontal colorbar') cbar = fig.colorbar(cax, ticks=[-1, 0, 1], orientation='horizontal') cbar.ax.set_xticklabels(['Low', 'Medium', 'High'])# horizontal colorbar plt.show() But, for a colorline object, which was referenced in the link given in my earlier email. --V |