[Matplotlib-users] How to remove vertical lines when plotting rotating phase
Hello, I'm plotting a rotating phase: # ipython --pylab x1 = linspace(0, 2*pi, 30) x = concatenate((x1,x1,x1,x1)) plot(x) The resulting plot has ugly vertical lines whenever x wraps from 2*pi back to zero. Does someone have a nice, general way to get to get rid of such lines? (the actual data is of course less predictable and regular than the example above). Best, -Nikolaus -- »Time flies like an arrow, fruit flies like a Banana.« PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C -- Better than sec? Nothing is better than sec when it comes to monitoring Big Data applications. Try Boundary one-second resolution app monitoring today. Free. http://p.sf.net/sfu/Boundary-dev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Fwd: How to remove vertical lines when plotting rotating phase
Forwarding an email that I sent directly to Nikolaus. (I think every other mailing list that I used defaults to something like Reply to list or Reply to all.) Warren -- Forwarded message -- From: Warren Weckesser warren.weckes...@enthought.com Date: Wed, Apr 4, 2012 at 11:18 AM Subject: Re: [Matplotlib-users] How to remove vertical lines when plotting rotating phase To: Nikolaus Rath nikol...@rath.org On Wed, Apr 4, 2012 at 10:48 AM, Warren Weckesser warren.weckes...@enthought.com wrote: On Wed, Apr 4, 2012 at 10:30 AM, Nikolaus Rath nikol...@rath.org wrote: Hello, I'm plotting a rotating phase: # ipython --pylab x1 = linspace(0, 2*pi, 30) x = concatenate((x1,x1,x1,x1)) plot(x) The resulting plot has ugly vertical lines whenever x wraps from 2*pi back to zero. Does someone have a nice, general way to get to get rid of such lines? (the actual data is of course less predictable and regular than the example above). You can use numpy.unwrap, e.g. plot(unwrap(x)) Warren You might not want the unwrapped effect. You can figure out where the big jumps occur, and plot the data in pieces with something like this example. It doesn't plot lines that jump by more than pi: - import numpy as np import matplotlib.pyplot as plt t = np.linspace(0, 10, 200) y = np.mod(2 * t * np.sin(0.5 * t), 2 * np.pi) jumps = np.r_[0, np.where(np.abs(np.diff(y)) np.pi)[0] + 1, y.size] for k in range(jumps.size-1): start, end = jumps[k:k + 2] plt.plot(t[start:end], y[start:end], 'b') plt.show() - I don't know if something like this already exists in matplotlib, or if there is some other technique that would be simpler. Warren -- Better than sec? Nothing is better than sec when it comes to monitoring Big Data applications. Try Boundary one-second resolution app monitoring today. Free. http://p.sf.net/sfu/Boundary-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] How to remove vertical lines when plotting rotating phase
On Wednesday, April 4, 2012, Nikolaus Rath wrote: Hello, I'm plotting a rotating phase: # ipython --pylab x1 = linspace(0, 2*pi, 30) x = concatenate((x1,x1,x1,x1)) plot(x) The resulting plot has ugly vertical lines whenever x wraps from 2*pi back to zero. Does someone have a nice, general way to get to get rid of such lines? (the actual data is of course less predictable and regular than the example above). Best, -Nikolaus Put [np.nan] between each complete rotation. Nans in a plot breaks the line. Ben Root -- Better than sec? Nothing is better than sec when it comes to monitoring Big Data applications. Try Boundary one-second resolution app monitoring today. Free. http://p.sf.net/sfu/Boundary-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Display problem on CentOS
Thanks again, Eric. I had been trying, and finally got a good result. My answer is installing PyQt4 for newer Python (v2.7.2) from sources. Here is the successful steps: 1. Install SIP from source (sip-4.13.2.tar.gz) at default directory 2. Install QtSDK from .run file (Qt_SDK_Lin64_online_v1_2_en.run) at /usr/local/QtSDK * To install Qt from source, we have to get additional libraries. It was very bothersome, so I used official .run file. 3. Install PyQt4 from source (PyQt-x11-gpl-4.9.1.tar.gz) When I did ./configure, I set these options: python ./configure.py -g -q /usr/local/QtSDK/Desktop/Qt/4.8.0/gcc/bin/qmake If not setting -q option, pre-installed Qt may be selected, and we may get DBusPendingCall errors. After above, I set backend and plotted line as below: import matplotlib matplotlib.use(Qt4Agg) import matplotlib.pyplot as plt plt.plot([1,2,4,3]) plt.show() Then I got plot window from PyQt4! :) Magician On 2012/04/01, at 19:42, matplotlib-users-requ...@lists.sourceforge.net wrote: Date: Sat, 31 Mar 2012 07:53:21 -1000 From: Eric Firing efir...@hawaii.edu Subject: Re: [Matplotlib-users] Display problem on CentOS To: matplotlib-users@lists.sourceforge.net Message-ID: 4f774491.5070...@hawaii.edu Content-Type: text/plain; charset=ISO-8859-1; format=flowed On 03/31/2012 04:02 AM, Magician wrote: Alexis Eric Thanks for your advices. I've been trying, but I still have some problems. I tried matplotlib.matplotlib_fname() and I found my silly mistake. Python answered '/usr/local/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc' My RC file was named .matplotlibrc. When the prefixed dot removed, it works perfectly. And I found to change the backends by using matplotlib.use() command. I tried all of them, but nothing worked (with errors). When using matplotlib.get_backend() on pre-installed python2.6, it said 'GTKAgg' and matplotlib.pyplot.show() exactly worked. So I tried to install PyGTK from source code, but it's fairly complicated. Is there an easy way to install backends for additionally installed Python? My python is v2.7.2. Can you find CentOS packages for any of the gui toolkits for your python version? pygtk, pyqt4, tkinter, wxpython--any of them? If so, you should be just about set. Only pygtk and tkinter would even require rebuilding mpl; pyqt4 and wxpython don't require any mpl extension code. Eric Magician On 2012/03/27, at 23:04, Alexis Praga wrote: You can check you are editing the correct configuration file with (in the Python shell) : import matplotlib matplotlib.matplotlib_fname() You can also try other backends. For a list, see : http://matplotlib.sourceforge.net/faq/usage_faq.html#what-is-a-backend On Tue, Mar 27, 2012 at 2:46 PM, Magicianf_magic...@mac.com wrote: Thank you, Alexis. I try to install PyQt4 and set Qt4Agg just now, but nothing displayed. Ummm...what's wrong...?? Magician On 2012/03/27, at 17:05, Alexis Praga wrote: I had the same problem on Debian. Editing the matplotlibrc (should be installed somewhere in your systeme) and changing the backend variable to Qt4Agg did the trick. On Tue, Mar 27, 2012 at 12:14 AM, Magicianf_magic...@mac.com wrote: Hi. I want to install Matplotlib from source code on CentOS. I've been using Matplotlib for a year. But this is the first time for me to install CentOS by myself. I installed CentOS 6.2 in basic install option. Next, I installed NumPy and Matplotlib. .matplotlibrc isn't set. It looks successfully installed, but when I type show() command, nothing appears. I can export PNG image by using savefig() command, so maybe I'm using invalid backend. How can I display plots with show() command? Magician -- Better than sec? Nothing is better than sec when it comes to monitoring Big Data applications. Try Boundary one-second resolution app monitoring today. Free. http://p.sf.net/sfu/Boundary-dev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] assigning a plot object to a figure
After trying hard to send a plot to my widget, I finally found a solution that works: get the figure from the widget! In short, it is has simple as: from pyqtgraph.Qt import QtGui, QtCore import matplotlib from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar from matplotlib.figure import Figure class MatplotlibWidget(QtGui.QWidget): Implements a Matplotlib figure inside a QWidget. Use getFigure() and redraw() to interact with matplotlib. Example:: mw = MatplotlibWidget() subplot = mw.getFigure().add_subplot(111) subplot.plot(x,y) mw.draw() def __init__(self, size=(5.0, 4.0), dpi=100): QtGui.QWidget.__init__(self) self.fig = Figure(size, dpi=dpi) self.canvas = FigureCanvas(self.fig) self.canvas.setParent(self) self.toolbar = NavigationToolbar(self.canvas, self) self.vbox = QtGui.QVBoxLayout() self.vbox.addWidget(self.toolbar) self.vbox.addWidget(self.canvas) self.setLayout(self.vbox) def getFigure(self): return self.fig def draw(self): self.canvas.draw() A special thanks to the pyqtgraph maintainer http://luke.campagnola.me/code/pyqtgraph/ From: Emmanuel Mayssat emays...@yahoo.com To: Emmanuel Mayssat emays...@yahoo.com; Eric Firing efir...@hawaii.edu; matplotlib-users@lists.sourceforge.net matplotlib-users@lists.sourceforge.net Sent: Tuesday, April 3, 2012 4:36 PM Subject: Re: [Matplotlib-users] assigning a plot object to a figure Although this work, I lose the position of the axes. How can I reposition the axes2 which was at 221 in fig2, to 221 in fig1 ? From: Emmanuel Mayssat emays...@yahoo.com To: Eric Firing efir...@hawaii.edu; matplotlib-users@lists.sourceforge.net matplotlib-users@lists.sourceforge.net Sent: Monday, April 2, 2012 3:20 PM Subject: Re: [Matplotlib-users] assigning a plot object to a figure Well, not sure if that is supported, but I found a way !: [...] self.fig1 = Figure(figsize=(width, height), dpi=dpi) self.fig2 = Figure(figsize=(width, height), dpi=dpi) self.axes1 = self.fig1.add_subplot(223) self.axes2 = self.fig2.add_subplot(221) [...] self.axes2.plot([0,1]) (1) self.axes2.set_figure(self.fig1) (2) self.fig1.add_axes(self.axes2) Note that (1) and (2) are required in that order! From the code above, if I show the fig1, then I see axes1 and axes2 on the figure Summary: I created the axes2 independently of fig1 PS: I want to use my axes2 as an object to sent to my Qt widget (a blank figure/canvas) -- Emmanuel From: Eric Firing efir...@hawaii.edu To: matplotlib-users@lists.sourceforge.net Sent: Sunday, April 1, 2012 1:36 PM Subject: Re: [Matplotlib-users] assigning a plot object to a figure On 03/30/2012 01:23 PM, Emmanuel Mayssat wrote: Hello all, I can create a figure and get the corresponding axes/plots for examples: 1/ fig = Figure(figsize=(width, height), dpi=dpi) ax = gif.add_subplot(111) 2/ fig, ax = plt.subplots() but I would like to create my plot independently from the figure and assign it to a figure I code I would like to do something like this my_ax = Axes(...) my_ax.plot(x,y) ax = my_ax or my_ax.set_figure(fig) How can I create the axes/plot object independently from the figure? As far as I can see, you can't. The figure is deeply embedded in the Axes object; that's why the figure is an argument in Axes.__init__(). Better yet, how can I assign an axe to a figure? I don't think you can. It looks to me like Axes.set_figure should be clearly marked as a private method, not to be used except in Axes.__init__(). Short of a major refactoring of mpl, I think you will need to find some other way of accomplishing your ultimate aim. Eric -- Emmanuel -- This SF email is sponsosred by: Try Windows Azure free for 90 days Click Here http://p.sf.net/sfu/sfd2d-msazure ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Better than sec? Nothing is better than sec when it comes to monitoring Big Data applications. Try Boundary one-second resolution app monitoring today. Free. http://p.sf.net/sfu/Boundary-dev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users-- Better than sec?
Re: [Matplotlib-users] Export 3D plot to 3D file format
On Tue, Mar 27, 2012 at 5:39 PM, klo uo klo...@gmail.com wrote: Ah mayavi... I find it complicated for building, and in Ubuntu repository (or launchpad) there is some old version I'll try later today to build it Thanks for your suggestion, Cheers On Tue, Mar 27, 2012 at 11:25 PM, Frédéric Vogt fv...@mso.anu.edu.auwrote: Is the savefig function what you're looking for ? http://github.enthought.com/mayavi/mayavi/auto/mlab_figure.html Note that as far as I know, the .mtl file associated with a given .obj file is not handled properly - all your colors will be white. Personally, I export in .vrml which suits my needs better, as it does handle colors in a satisfactory way. With the way matplotlib is designed and structured, it may be a while before that would be possible. It wouldn't be impossible, mind you, but I just haven't thought about that. Could you file a wishlist item on Github? Maybe I could steal some code from Mayavi for this idea... In the meantime, Mayavi would be your best bet, though. Thanks, Ben Root -- Better than sec? Nothing is better than sec when it comes to monitoring Big Data applications. Try Boundary one-second resolution app monitoring today. Free. http://p.sf.net/sfu/Boundary-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] corrupt pdf of histogram
On Wed, Mar 28, 2012 at 2:27 PM, Jouni K. Seppänen j...@iki.fi wrote: sanders sand...@knmi.nl writes: If keywords fill=False and log=True, then after saving, the png looks fine but the histogram in the pdf is mixed up. Confirmed, thanks for the report. I filed this at https://github.com/matplotlib/matplotlib/issues/804 I ran into something like this with filled plots originally saved as eps files and then converted into a pdf. Didn't need log=True, though. The eps files were fine, but depending on how I converted (pstopdf or ps2pdf, I forget which) it would get messed up. I will double-check my comments I made in a Makefile about this to see if it might be related. Ben Root -- Better than sec? Nothing is better than sec when it comes to monitoring Big Data applications. Try Boundary one-second resolution app monitoring today. Free. http://p.sf.net/sfu/Boundary-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users