## matplotlib-users

 [Matplotlib-users] Scaling the axis values from list indices to meaningful values From: shamster - 2009-10-02 23:21:14 ```My current plot takes data to construct a 2d histogram. In gnuplot i would accomplish this by using splot, dgrid3d, and pulling in a 'matrix' data file. The code below has produced nearly what I need. However, the axes limits are set based on the indices of the incoming data (i.e. the number of rows or columns in my data matrix) instead of something meaningful. For example, my x-axis is set from 0 to 2000, but I'd like it to span from -1 to +1 because my x-data is a cosine function... I would imagine that some type of axis-scaling function would take a function to scale the labels... something akin to: scale_axis(lambda x: x*.001-1.0, ax) would do the trick of scaling my (0, 2000) data to the (-1.0, 1.0) extents. Is there any such functionality to actually scale the values of the axis tick-labels? 1 import sys 2 from scipy import * 3 import scipy.io.array_import 4 5 # plotting libs 6 import matplotlib.pyplot as plt 7 from pylab import * 8 9 10 11 file = scipy.io.array_import.read_array(sys.argv[1]) 12 data = [] 13 14 for i in range(len(file[0])): 15 data.append(file[:,i]) 16 17 # create a figure 18 fig = figure(1) 19 20 cmBase = cm.jet # choose a colormap to use for the plot 21 22 # This processes the data and adds the colored 2D histogram to the figure 23 im = imshow(data, interpolation='bilinear') 24 # A little magic to create a colorbar - legend for the plot 25 plt.colorbar(im) 26 27 # Turn on the X-Y grid 28 grid(True) 29 30 # Pass go - collect \$200 31 draw() 32 show() -- View this message in context: http://www.nabble.com/Scaling-the-axis-values-from-list-indices-to-meaningful-values-tp25724127p25724127.html Sent from the matplotlib - users mailing list archive at Nabble.com. ```
 Re: [Matplotlib-users] Scaling the axis values from list indices to meaningful values From: Jae-Joon Lee - 2009-10-05 03:01:26 ```use "extent" argument. http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.imshow -JJ On Fri, Oct 2, 2009 at 7:21 PM, shamster wrote: > > My current plot takes data to construct a 2d histogram. In gnuplot i would > accomplish this by using splot, dgrid3d, and pulling in a 'matrix' data > file. The code below has produced nearly what I need. However, the axes > limits are set based on the indices of the incoming data (i.e. the number of > rows or columns in my data matrix) instead of something meaningful. For > example, my x-axis is set from 0 to 2000, but I'd like it to span from -1 to > +1 because my x-data is a cosine function... > > I would imagine that some type of axis-scaling function would take a > function to scale the labels... something akin to: > > scale_axis(lambda x: x*.001-1.0, ax) > > would do the trick of scaling my (0, 2000) data to the (-1.0, 1.0) extents. > Is there any such functionality to actually scale the values of the axis > tick-labels? > > > > > > >  1 import sys >  2 from scipy import * >  3 import scipy.io.array_import >  4 >  5 # plotting libs >  6 import matplotlib.pyplot as plt >  7 from pylab import * >  8 >  9 >  10 >  11 file = scipy.io.array_import.read_array(sys.argv[1]) >  12 data = [] >  13 >  14 for i in range(len(file[0])): >  15     data.append(file[:,i]) >  16 >  17 # create a figure >  18 fig = figure(1) >  19 >  20 cmBase = cm.jet   # choose a colormap to use for the plot >  21 >  22 # This processes the data and adds the colored 2D histogram to the > figure >  23 im = imshow(data, interpolation='bilinear') >  24 # A little magic to create a colorbar - legend for the plot >  25 plt.colorbar(im) >  26 >  27 # Turn on the X-Y grid >  28 grid(True) >  29 >  30 # Pass go - collect \$200 >  31 draw() >  32 show() > > > -- > View this message in context: http://www.nabble.com/Scaling-the-axis-values-from-list-indices-to-meaningful-values-tp25724127p25724127.html > Sent from the matplotlib - users mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry® Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9-12, 2009. Register now! > http://p.sf.net/sfu/devconf > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ```