On Sun, Aug 10, 2008 at 8:06 AM, Boris Barbour <[EMAIL PROTECTED]> wrote: > > Hi, > > I have lots of data acquired via analogue to digital conversion. The data is > consequently represented as integers (often 16 bit resolution). To obtain the > correct signal and plot it, these data must of course be multiplied by a > floating point scale factor. This seems potentially wasteful of resources > (time and memory), especially as I would prefer to keep the original data > untouched. > > It occurs to me that a more efficient plotting method would be to plot the > original data but scale the axes by the appropriate factor. In that way a > simple numpy array view could be passed to plot. Does a method for doing this > exist? I think I can do it in a rather convoluted way by plotting the > original data and then superimposing empty axes at the adjusted scale. > However, I haven't yet tested this and I'm a bit skeptical about the overhead > of two plots. Another possibility might be the units mechanism, but according > to the documentation that is discouraged, and it might be awkward to > implement.
The easiest way is to define a custom formatter -- this is responsible for taking your numeric data and converting it to strings for the tick labels and navigation toolbar coordinate reporting. Eg import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as ticker t = np.arange(1000)*0.01 s = (np.random.rand(1000)*4096).astype(int) # this controls the formatting of the tick labels class VoltFormatter(ticker.Formatter): """ take input and convert to +/- 5V 0->-5, 2048->0, 4096->5 """ def __call__(self, x, pos=None): return '%1.2f'%(5*(x-2048)/4096.) formatter = VoltFormatter() fig = plt.figure() ax = fig.add_subplot(111) ax.plot(t, s) ax.yaxis.set_major_formatter(formatter) plt.show() One problem with this solution is that the tick choices are poor, since the tick locator doesn't know where to put multiple of volts. To solve this, you can write your own locator, eg as described in the user's guide, to place ticks on multiples of the integer scale. But as Eric notes, mpl will be converting your data under the hoods to doubles anyway, so you won't be getting any space and cpu savings ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users