Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## matplotlib-users

 [Matplotlib-users] Polyfit help From: Brian B. - 2005-03-30 20:59:26 Hello, I graph of weather data from a CGI script using the Agg backend only. The graph is a common time vs. temperature 2D line plot. Since the graph plots every n minutes, the lines on the graph tend to look pointed and not very aesthetically pleasing (as many people have informed me.) I did some research and found I needed to do curve fitting. I'm trying to use 8th order polynomial fitting. I have found a sample on the Web that shows how to use matplotlib to do a best-fit line from polyfit, but I want a curve that follows the curve of weather temperature data. I plot the data using a list of X-coordinates and a list of Y-coordinates. I assume I can call polyfit with (x,y,8) for 8th order polynomial fitting. However, I am not sure what to do with the results. I have tried to translate the 1st order polyfit example for my needs but I don't think I am using the polyfit data correctly. Also, it has been suggested that a spline or Butterworth filter on the data may yield more predictable results. I have found some of this functionality in SciPy and a nifty module in a language called Octave. Would matplotlib benefit from this? Any assistance is much appreciated. I'm just starting out on this type of stuff but it is fascinating to work with! Thank you, Brian 
 Re: [Matplotlib-users] Polyfit help From: John Hunter - 2005-03-31 14:54:53 >>>>> "Brian" == Brian B writes: Brian> Hello, I graph of weather data from a CGI script using the Brian> Agg backend only. The graph is a common time Brian> vs. temperature 2D line plot. Since the graph plots every n Brian> minutes, the lines on the graph tend to look pointed and Brian> not very aesthetically pleasing (as many people have Brian> informed me.) I did some research and found I needed to do Brian> curve fitting. Brian> I'm trying to use 8th order polynomial fitting. I have Brian> found a sample on the Web that shows how to use matplotlib Brian> to do a best-fit line from polyfit, but I want a curve that Brian> follows the curve of weather temperature data. Brian> I plot the data using a list of X-coordinates and a list of Brian> Y-coordinates. I assume I can call polyfit with (x,y,8) Brian> for 8th order polynomial fitting. However, I am not sure Brian> what to do with the results. I have tried to translate the Brian> 1st order polyfit example for my needs but I don't think I Brian> am using the polyfit data correctly. You would need to use polyval to get the results of polyfit (there is an example in the matplotlib Users Guide in the Cookbook chapter for a 3rd order fit), but I don't think you want to use an 8-th order polynomial for this -- as you indicate below, a spline or a filter is a better choice. Brian> Also, it has been suggested that a spline or Butterworth Brian> filter on the data may yield more predictable results. I Brian> have found some of this functionality in SciPy and a nifty Brian> module in a language called Octave. Would matplotlib Brian> benefit from this? Use spline if you want a curve that passes through all your data, use butterworth or convolution if you want to smooth your data. scipy is your best bet -- scipy spline and a butterworth filter examples from my scipy examples directory are included. In general, we try to stay focused on plotting in matplotlib rather than algorithms, and leave algorithms to the scipy folks. They are working hard on getting a modular package that is easy to install. I think it would be useful to provide some wrappers around scipy in the matplotlib.mlab module that exposed a matlab interface to some of their algorithms, with imports done in such a way that having the additional scipy functionality would be optional Here is a scipy spline example, plotted with mpl from scipy import arange, sin, pi, interpolate from pylab import plot, show # Cubic-spline t = arange(0, 2.0, 0.1) y = sin(2*pi*t) tck = interpolate.splrep(t, y, s=0) tnew = arange(0, 2.0, 0.01) ynew = interpolate.splev(tnew, tck, der=0) plot(t, y, 'o', tnew, ynew) show() And here is a butterworth filter. Note that filters can introduce phase shifts in your data (illustrated in this example) so use with caution! from __future__ import division from scipy import signal, arange, sin, pi, linspace, transpose from RandomArray import normal from pylab import plot, show, subplot from scipy.signal import buttord, butter, lfilter dt = 0.001 t = arange(0.0, 10.0, dt) nse = normal(0.0, 0.1, t.shape) #s = s = normal(0.0, 1.0, (len(t),22)) for i in range(22): s[:,i] += sin(2*pi*t) lpcf = 3 lpsf = 5 Nyq = 1/(2*dt) Rp = 2 Rs = 20 Wp = lpcf/Nyq Ws = lpsf/Nyq [n,Wn] = buttord(Wp,Ws,Rp,Rs) [b,a] = butter(n,Wn) xlp = transpose(lfilter(b,a,transpose(s))) subplot(311) plot(t, s[:,0]) subplot(312) plot(t, xlp[:,0]) subplot(313) plot(t, xlp[:,1]) show() Brian> Any assistance is much appreciated. I'm just starting out Brian> on this type of stuff but it is fascinating to work with! Have fun! JDH 
 [Matplotlib-users] Problem UsingTex From: kristen kaasbjerg - 2005-07-30 10:18:56 Dear John When running the tex_demo.py script I just get a gray figure canvas (no curves or anything) and the following error message: __________________________________________________ Exception in Tkinter callback Traceback (most recent call last): File "C:\Python24\lib\lib-tk\Tkinter.py", line 1345, in __call__ return self.func(*args) File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", line 148, in resize self.show() File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", line 151, in draw FigureCanvasAgg.draw(self) File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_agg.py", line 381, in draw self.figure.draw(renderer) File "C:\Python24\Lib\site-packages\matplotlib\figure.py", line 511, in draw for a in self.axes: a.draw(renderer) File "C:\Python24\Lib\site-packages\matplotlib\axes.py", line 1387, in draw self.xaxis.draw(renderer) File "C:\Python24\Lib\site-packages\matplotlib\axis.py", line 552, in draw tick.draw(renderer) File "C:\Python24\Lib\site-packages\matplotlib\axis.py", line 151, in draw if self.label1On: self.label1.draw(renderer) File "C:\Python24\Lib\site-packages\matplotlib\text.py", line 848, in draw self._mytext.draw(renderer) File "C:\Python24\Lib\site-packages\matplotlib\text.py", line 335, in draw bbox, info = self._get_layout(renderer) File "C:\Python24\Lib\site-packages\matplotlib\text.py", line 184, in _get_layout w,h = renderer.get_text_width_height( File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_agg.py", line 241, in get_text_width_height Z = self.texmanager.get_rgba(s, size, dpi, rgb) File "C:\Python24\Lib\site-packages\matplotlib\texmanager.py", line 296, in get_rgba X = readpng(pngfile) RuntimeError: _image_module::readpng could not open PNG file C:\Documents and Settings\Kristen\.matplotlib\tex.cache\30565a8911a6bb487e3745c0ea3c8224_96.png for reading ______________________________________________________ Any idea of what I'm missing?? Kristen __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com 
 Re: [Matplotlib-users] Problem UsingTex From: Gary Ruben - 2005-07-30 12:57:21 Hi Kristen, Last time I looked (a couple of weeks ago), there were problems in this area of matplotlib with LaTeX not being invoked properly. Can you please tell us what version of Windows, matplotlib and which LaTeX distribution you are using. I was intending to have another look at the code in a week or so from now. I'm unable to spend time on it until then. However, it looks like someone has made more recent changes to the relevant code, so I'd encourage you to try the latest version of matplotlib if the version you're using is more that a couple of weeks old. You may find that the problem you are seeing has been fixed. Please report back if you have success after doing this. Gary R. kristen kaasbjerg wrote: > Dear John > > When running the tex_demo.py script I just get a gray > figure canvas (no curves or anything) and the > following error message: > __________________________________________________ > Exception in Tkinter callback > Traceback (most recent call last): > File "C:\Python24\lib\lib-tk\Tkinter.py", line 1345, > in __call__ > return self.func(*args) > File > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", > line 148, in resize > self.show() > File > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", > line 151, in draw > FigureCanvasAgg.draw(self) > File > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_agg.py", > line 381, in draw > self.figure.draw(renderer) > File > "C:\Python24\Lib\site-packages\matplotlib\figure.py", > line 511, in draw > for a in self.axes: a.draw(renderer) > File > "C:\Python24\Lib\site-packages\matplotlib\axes.py", > line 1387, in draw > self.xaxis.draw(renderer) > File > "C:\Python24\Lib\site-packages\matplotlib\axis.py", > line 552, in draw > tick.draw(renderer) > File > "C:\Python24\Lib\site-packages\matplotlib\axis.py", > line 151, in draw > if self.label1On: self.label1.draw(renderer) > File > "C:\Python24\Lib\site-packages\matplotlib\text.py", > line 848, in draw > self._mytext.draw(renderer) > File > "C:\Python24\Lib\site-packages\matplotlib\text.py", > line 335, in draw > bbox, info = self._get_layout(renderer) > File > "C:\Python24\Lib\site-packages\matplotlib\text.py", > line 184, in _get_layout > w,h = renderer.get_text_width_height( > File > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_agg.py", > line 241, in get_text_width_height > Z = self.texmanager.get_rgba(s, size, dpi, rgb) > File > "C:\Python24\Lib\site-packages\matplotlib\texmanager.py", > line 296, in get_rgba > X = readpng(pngfile) > RuntimeError: _image_module::readpng could not open > PNG file C:\Documents and > Settings\Kristen\.matplotlib\tex.cache\30565a8911a6bb487e3745c0ea3c8224_96.png > for reading > ______________________________________________________ > > Any idea of what I'm missing?? > > Kristen 
 Re[2]: [Matplotlib-users] Problem UsingTex From: Alan G Isaac - 2005-07-30 13:03:22 On Sat, 30 Jul 2005, Gary Ruben apparently wrote: > Last time I looked (a couple of weeks ago), there were problems in this > area of matplotlib with LaTeX not being invoked properly. How does Matplotlib find TeX? Can it be directed to a specific distribution? Thanks, Alan 
 Re: [Matplotlib-users] Problem UsingTex From: Darren Dale - 2005-07-30 13:05:45 On Saturday 30 July 2005 08:52 am, Gary Ruben wrote: > Hi Kristen, > Last time I looked (a couple of weeks ago), there were problems in this > area of matplotlib with LaTeX not being invoked properly. > Can you please tell us what version of Windows, matplotlib and which > LaTeX distribution you are using. > I was intending to have another look at the code in a week or so from > now. I'm unable to spend time on it until then. However, it looks like > someone has made more recent changes to the relevant code, so I'd > encourage you to try the latest version of matplotlib if the version > you're using is more that a couple of weeks old. You may find that the > problem you are seeing has been fixed. > Please report back if you have success after doing this. > Gary R. Sascha found some problems with the way commands were being passed, which only effected windows. I commited her patches. Sascha, could you comment?. 
 Re: [Matplotlib-users] Problem UsingTex From: kristen kaasbjerg - 2005-07-30 13:27:04 Hi Gary I'm using windows XP, matplotlib 0.83.2, python 2.4 and latex2e. Kristen --- Gary Ruben wrote: > Hi Kristen, > Last time I looked (a couple of weeks ago), there > were problems in this > area of matplotlib with LaTeX not being invoked > properly. > Can you please tell us what version of Windows, > matplotlib and which > LaTeX distribution you are using. > I was intending to have another look at the code in > a week or so from > now. I'm unable to spend time on it until then. > However, it looks like > someone has made more recent changes to the relevant > code, so I'd > encourage you to try the latest version of > matplotlib if the version > you're using is more that a couple of weeks old. You > may find that the > problem you are seeing has been fixed. > Please report back if you have success after doing > this. > Gary R. > > kristen kaasbjerg wrote: > > Dear John > > > > When running the tex_demo.py script I just get a > gray > > figure canvas (no curves or anything) and the > > following error message: > > __________________________________________________ > > Exception in Tkinter callback > > Traceback (most recent call last): > > File "C:\Python24\lib\lib-tk\Tkinter.py", line > 1345, > > in __call__ > > return self.func(*args) > > File > > > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", > > line 148, in resize > > self.show() > > File > > > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", > > line 151, in draw > > FigureCanvasAgg.draw(self) > > File > > > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_agg.py", > > line 381, in draw > > self.figure.draw(renderer) > > File > > > "C:\Python24\Lib\site-packages\matplotlib\figure.py", > > line 511, in draw > > for a in self.axes: a.draw(renderer) > > File > > > "C:\Python24\Lib\site-packages\matplotlib\axes.py", > > line 1387, in draw > > self.xaxis.draw(renderer) > > File > > > "C:\Python24\Lib\site-packages\matplotlib\axis.py", > > line 552, in draw > > tick.draw(renderer) > > File > > > "C:\Python24\Lib\site-packages\matplotlib\axis.py", > > line 151, in draw > > if self.label1On: self.label1.draw(renderer) > > File > > > "C:\Python24\Lib\site-packages\matplotlib\text.py", > > line 848, in draw > > self._mytext.draw(renderer) > > File > > > "C:\Python24\Lib\site-packages\matplotlib\text.py", > > line 335, in draw > > bbox, info = self._get_layout(renderer) > > File > > > "C:\Python24\Lib\site-packages\matplotlib\text.py", > > line 184, in _get_layout > > w,h = renderer.get_text_width_height( > > File > > > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_agg.py", > > line 241, in get_text_width_height > > Z = self.texmanager.get_rgba(s, size, dpi, > rgb) > > File > > > "C:\Python24\Lib\site-packages\matplotlib\texmanager.py", > > line 296, in get_rgba > > X = readpng(pngfile) > > RuntimeError: _image_module::readpng could not > open > > PNG file C:\Documents and > > > Settings\Kristen\.matplotlib\tex.cache\30565a8911a6bb487e3745c0ea3c8224_96.png > > for reading > > > ______________________________________________________ > > > > Any idea of what I'm missing?? > > > > Kristen > > > > > ------------------------------------------------------- > SF.Net email is sponsored by: Discover Easy Linux > Migration Strategies > from IBM. Find simple to follow Roadmaps, > straightforward articles, > informative Webcasts and more! Get everything you > need to get up to > speed, fast. > http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs 
 Re: [Matplotlib-users] Problem UsingTex From: Gary Ruben - 2005-07-30 13:47:46 Hi Kristen, Looks like you're using the latest version of the relevant file from cvs, so I'm not sure what's going on. We'll have to hope for comment from the others. I just wanted to say thanks for that version information which may help me when I look at this stuff again in a couple of weeks. I hope others can sort out your problem in the meantime. Gary R. kristen kaasbjerg wrote: > Hi Gary > > I'm using windows XP, matplotlib 0.83.2, python 2.4 > and latex2e. > > Kristen 
 Re: [Matplotlib-users] Problem UsingTex From: Alan G Isaac - 2005-07-30 13:03:21 On Sat, 30 Jul 2005, kristen kaasbjerg apparently wrote: > RuntimeError: _image_module::readpng could not open > PNG file C:\Documents and > Settings\Kristen\.matplotlib\tex.cache\30565a8911a6bb487e3745c0ea3c8224_96.png > for reading > ______________________________________________________ > Any idea of what I'm missing?? Not really, but I wonder if it is related to my problem below. Both look like a temp file cannot be found. I am on Win2000; how about you? Alan Isaac Traceback (most recent call last): File "C:\temp8.py", line 30, in ? savefig('/temp.eps') File "C:\Python24\Lib\site-packages\matplotlib\pylab.py", line 773, in savefig return fig.savefig(*args, **kwargs) File "C:\Python24\Lib\site-packages\matplotlib\figure.py", line 636, in savefig self.canvas.print_figure(*args, **kwargs) File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", line 179, in print_figure agg.print_figure(filename, dpi, facecolor, edgecolor, orientation) File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_agg.py", line 474, in print_figure ps.print_figure(filename, dpi, facecolor, edgecolor, orientation) File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_ps.py", line 1103, in print_figure shutil.move(epsfile, outfile) File "C:\Python24\lib\shutil.py", line 189, in move copy2(src,dst) File "C:\Python24\lib\shutil.py", line 92, in copy2 copyfile(src, dst) File "C:\Python24\lib\shutil.py", line 47, in copyfile fsrc = open(src, 'rb') IOError: [Errno 2] No such file or directory: '80bc875819e5bf1b449889aadd91b3af.eps' 
 Re: [Matplotlib-users] Problem UsingTex From: Darren Dale - 2005-07-30 14:24:07 On Saturday 30 July 2005 06:18 am, kristen kaasbjerg wrote: > Dear John > > When running the tex_demo.py script I just get a gray > figure canvas (no curves or anything) and the > following error message: [...] > "C:\Python24\Lib\site-packages\matplotlib\texmanager.py", > line 296, in get_rgba > X = readpng(pngfile) > RuntimeError: _image_module::readpng could not open > PNG file C:\Documents and > Settings\Kristen\.matplotlib\tex.cache\30565a8911a6bb487e3745c0ea3c8224_96. >png for reading > ______________________________________________________ > > Any idea of what I'm missing?? Do you have dvipng installed? -- Darren 
 [Matplotlib-users] UsingTex: Nice thing to know and more problems From: kristen kaasbjerg - 2005-08-01 11:10:42 Hi matplotliber's (windows users) A few days ago I reported problems with the tex_demo.py script. Some solutions have been found meanwhile. First of all, matplotlibrc is NOT put in the intended directory upon istallation. It resides in the old share\matplotlib\. This must be done manually!! Secondly, when using TeX to create figure text, make sure that the directories where dvipng.exe, latex.exe, gs.exe etc are present in the system variable Path. For most latex/miktex installation this will probably be: C:\texmf\miktex\bin and C:\gs\. I have still not made it work using the PS backend. Somewhere there is an eps and tex file that has not been put in the .matplotlib\tex.cache directory. Also, much of the text doesn't come out correctly in the figures, so there are still problems when using TeX on Windows!! Kristen __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com 
 Re: [Matplotlib-users] UsingTex: Nice thing to know and more problems From: Gary Ruben - 2005-08-01 12:37:16 Hi Kristen, The PS backend is broken on my Win2k system too. I can only save as png, which isn't all that useful. I reported this a few weeks ago and I hope to get a chance to look at it next week to see if I can work out what's going on. It's good to get confirmation that it's not just my Windows installation that's doing this. Gary R. kristen kaasbjerg wrote: > Hi matplotliber's (windows users) > > A few days ago I reported problems with the > tex_demo.py script. Some solutions have been found > meanwhile. > > First of all, matplotlibrc is NOT put in the intended > directory upon istallation. It resides in the old > share\matplotlib\. This must be done manually!! > > Secondly, when using TeX to create figure text, make > sure that the directories where dvipng.exe, latex.exe, > gs.exe etc are present in the system variable Path. > For most latex/miktex installation this will probably > be: C:\texmf\miktex\bin and C:\gs\. > > I have still not made it work using the PS backend. > Somewhere there is an eps and tex file that has not > been put in the .matplotlib\tex.cache directory. > > Also, much of the text doesn't come out correctly in > the figures, so there are still problems when using > TeX on Windows!! > > Kristen 
 Re: [Matplotlib-users] UsingTex: Nice thing to know and more problems From: Darren Dale - 2005-08-01 12:47:22 On Monday 01 August 2005 08:36 am, Gary Ruben wrote: > The PS backend is broken on my Win2k system too. I can only save as png, > which isn't all that useful. I reported this a few weeks ago and I hope > to get a chance to look at it next week to see if I can work out what's > going on. > It's good to get confirmation that it's not just my Windows installation > that's doing this. Do you mean ps is broken with TeX support, or it is broken period? I will defend in a couple of weeks, so unfortunately I don't have time to bug hunt for a while. I should be back on the ball soon. Darren 
 Re: [Matplotlib-users] UsingTex: Nice thing to know and more problems From: Gary Ruben - 2005-08-01 14:58:15 Darren Dale wrote: > On Monday 01 August 2005 08:36 am, Gary Ruben wrote: > Do you mean ps is broken with TeX support, or it is broken period? Just the TeX->ps support is broken. 
 Re: [Matplotlib-users] UsingTex: Nice thing to know and more problems From: John Hunter - 2005-08-01 13:47:01 >>>>> "kristen" == kristen kaasbjerg writes: kristen> First of all, matplotlibrc is NOT put in the intended kristen> directory upon istallation. It resides in the old kristen> share\matplotlib\. This must be done manually!! There seems to be some confusion on this point, because Mark Bakker reported the same problem. matplotlib has never move the rc file from the default location share\matplotlib to the user location, because new installs would overwrite the user specific configuration. I think the confusion is that on windows, we never had a default user location for the rc file. I'll explain how it has always worked under linux/unix; maybe this will make it clear how it should now work under windows. matplotlib installs the rc file to /usr/share/matplotlib/matplotlibrc. You can copy this file to your configuration directory, HOME/.matplotlibrc, and this file will be used first if it exists. That way future installs to /usr/share/matplotlib will not mess up your local configurations. On windows, the default path is c:\Python23\share\matplotlib. If you want to customize this file, you should move it to C:\Documents and Settings\yourname\.matplotlib. Could you all test with a clean install of matplotlig (remove site-packages/matplotlib, share/matplotlib and C:\Documents and Settings\yourname\.matplotlib before reinstalling) that this procedure works properly? Thanks, JDH kristen> Secondly, when using TeX to create figure text, make sure kristen> that the directories where dvipng.exe, latex.exe, gs.exe kristen> etc are present in the system variable Path. For most kristen> latex/miktex installation this will probably be: kristen> C:\texmf\miktex\bin and C:\gs\. kristen> I have still not made it work using the PS backend. kristen> Somewhere there is an eps and tex file that has not been kristen> put in the .matplotlib\tex.cache directory. Could you update the UsingTex wiki at http://www.scipy.org/wikis/topical_software/UsingTex with this information, under a win32 section? Thanks, JDH