From: Stephan M. <zw...@we...> - 2011-02-16 15:16:27
|
Hi, I am trying to display some complex values in a polar plot. Displaying linear magnitude vs. angle - of course - works without any issues. But I'd rather display the logarithmic magnitute vs. angle. Since the data for the radius gets negative then, it'll be wrapped around / rotated by 180deg by matplotlib. How can I display negative values for the radius w/o having them rotated by 180deg? Of course I can add an offset to the data before plotting it but since my plot is interactive and I use the xdata/ydata of events I'd like them to represent the real data, without an offset. I thought it might be possible to achieve with a custom transformation but I don't actually get it to work. -Stephan -- View this message in context: http://old.nabble.com/Polar-plot---problem-with-negative-values-for-radius-tp30936638p30936638.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
From: Benjamin R. <ben...@ou...> - 2011-02-16 19:43:35
|
On Wed, Feb 16, 2011 at 9:16 AM, Stephan Markus <zw...@we...> wrote: > > Hi, > > I am trying to display some complex values in a polar plot. Displaying > linear magnitude vs. angle - of course - works without any issues. But I'd > rather display the logarithmic magnitute vs. angle. Since the data for the > radius gets negative then, it'll be wrapped around / rotated by 180deg by > matplotlib. > > How can I display negative values for the radius w/o having them rotated by > 180deg? > > Of course I can add an offset to the data before plotting it but since my > plot is interactive and I use the xdata/ydata of events I'd like them to > represent the real data, without an offset. I thought it might be possible > to achieve with a custom transformation but I don't actually get it to > work. > > -Stephan > -- > View this message in context: > http://old.nabble.com/Polar-plot---problem-with-negative-values-for-radius-tp30936638p30936638.html > Sent from the matplotlib - users mailing list archive at Nabble.com. > > Stephan, >From the polar axes object, you can call ax.set_rscale('log') and that will automatically make the radial ticks scale and label the axes properly. You can then input the original data as you would without worry of negative values. Let us know how that works for you! Ben Root |
From: Stephan M. <zw...@we...> - 2011-02-17 09:20:00
|
Ben, I should have mentioned that I already tried that. When I set the rscale to 'log' the plot crashes when zooming or mpl cannot even create it. Maybe some example code will help: ---------------- from numpy import arange, sin, pi, cos, ones from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg from matplotlib.figure import Figure import Tkinter as Tk root = Tk.Tk() f = Figure(figsize=(5,4), dpi=100) ax = f.add_subplot(111, projection='polar') t = arange(0.0,2*pi,0.01) s1 = ones(len(t))*10 ax.set_rscale('log') ax.plot(t,s1) canvas = FigureCanvasTkAgg(f, master=root) canvas.show() canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) toolbar = NavigationToolbar2TkAgg(canvas, root) toolbar.update() canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) Tk.mainloop() ---------------- Using this code the plot will show up but you can see the 10^-1 and 10^-2 tick labels overlapping in the center. Ok, it shouldn't be a big deal to get rid of them. The major problem is if you try to zoom out, the tick labels move away from the center and if you try to zoom into the plot it eventually throws an exception "ValueError: cannot convert float NaN to integer". If you try to plot smaller values (e.g. replacing the line 's1 = ones(len(t))*10' with 's1 = ones(len(t))') mpl also throws an ValueError exception and does not even create the plot. Let me know if you need full tracebacks. Btw: I am using Matplotlib 1.0.1 and Python 2.6.0 on Windows 64. -- View this message in context: http://old.nabble.com/Polar-plot---problem-with-negative-values-for-radius-tp30936638p30947935.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
From: Stephan M. <zw...@we...> - 2011-02-17 10:12:21
|
Small update: I tried the very same code with MPL 1.0.1 and Python 2.5.0 on Linux 64 and Python 2.5.4 on Win32 and it runs w/o throwing any exceptions there! But: the behaviour is still not that what I expected. Still these issues are remaining: - the smallest magnitude (center magnitude in other words) is 0.1 and I'd like to display way smaller values - the smallest magnitude doesn't even change when zooming - the grid lines and ticks do not show as I'd expect (see my last message) when zooming That's why I'd rather stick to a linear scale, doing my own logarithmic conversion, limit my data at lowest value I need and just use an offset for the scale. -- View this message in context: http://old.nabble.com/Polar-plot---problem-with-negative-values-for-radius-tp30936638p30948265.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
From: Benjamin R. <ben...@ou...> - 2011-02-17 15:10:14
|
On Thu, Feb 17, 2011 at 4:12 AM, Stephan Markus <zw...@we...> wrote: > > Small update: > > I tried the very same code with MPL 1.0.1 and Python 2.5.0 on Linux 64 and > Python 2.5.4 on Win32 and it runs w/o throwing any exceptions there! > > But: the behaviour is still not that what I expected. Still these issues > are > remaining: > - the smallest magnitude (center magnitude in other words) is 0.1 and I'd > like to display way smaller values > - the smallest magnitude doesn't even change when zooming > - the grid lines and ticks do not show as I'd expect (see my last message) > when zooming > > > That's why I'd rather stick to a linear scale, doing my own logarithmic > conversion, limit my data at lowest value I need and just use an offset for > the scale. > I see what you mean. This problem is almost identical to another thread going on where we can't seem to correctly do log scale for 3d plots. The tick locators are in the wrong positions (the major ticks should be evenly spaced) and the error message is similar to one I have been encountering in mplot3d. I will look a little further into this and see if I can kill two birds with one stone... Ben Root |
From: Stephan M. <zw...@we...> - 2011-02-21 09:19:46
|
I am using a workaround now. But that is a hackery solution. Before plotting my data I convert it to dBs and limit it to the lowest value I want to display. Then I plot it using a regular polar plot with a custom formatting function that sets the tick labels with respect to the data offset. Since I use a custom Navigation-Toolbar anyways it was no big deal to add the few necessery lines of codes to handle the offset there, too. The plot now looks exactly as I want it. But: I'd still prefer using a scale that does all the work in the background. -- View this message in context: http://old.nabble.com/Polar-plot---problem-with-negative-values-for-radius-tp30936638p30975519.html Sent from the matplotlib - users mailing list archive at Nabble.com. |