I'm trying to plot a series of plots one plot at a time. When a plot is displayed I want to be able to interact with it (i.e. zoom, pan, etc.) and wait until I'm done before the next plot is displayed.
I saw the post matplotlib plot and then wait for raw input, but I couldn't get it to work.
I'm using Spyder and Python 3.4.
Below is the code snippet of what I'd like to do. However the plots seem to get blocked by the waiting for input.
for i in range(4):
plt.figure()
plt.plot([x for x in range(100)],'x')
plt.show(block=False)
a=input('next plot')
If you are looking for interactive plots in Python, you might want to take a look at the Charts library. It enables you to use the excellent Highcharts javascript library to make beautiful and interactive plots. Highcharts uses the HTML svg tag so all your charts are actually vector images.
Some features:
Vector plots which you can download in .png, .jpg and .svg formats so you will never run into resolution problems
Interactive charts (zoom, slide, hover over points, ...)
Usable in an IPython notebook
Explore hundreds of data structures at the same time using the asynchronous plotting capabilities.
Disclaimer: I'm the developer of the library
I believe this is resolved in the recent matplotlib v.2.0.0 release. At least it resolved this problem for me.
Related
I am plotting multiples signals overlapping in one figure using matplotlib and then saving it in pdf/eps using matplotlib.pyplot.savefig, the problem is that when I try to insert the figure in a pdf-latex file, it takes like 1.5 min to load because it starts rendering every plot. Is there any way to properly save or create these plots in one figure?
The final pdf works perfectly when I use preview on macOS, regularly when I use edge or chrome navigators and it is a disaster if I use adobe-reader. I am looking for a multiplatform solution.
I'm having trouble with a plot because an input prevents the plot to be displayed. I have a large code which manipulate some data and plot it, then ask some questions about the plot (with which then makes another plot). Im running the code from another notebook so, although the plot and the input are in diferent cells, the plot it isn't displayed until i make the input,here is a short example of the problem:
%matplotlib nbagg
import matplotlib.pyplot as plt
plt.plot([1,2,3,4,5,6,7,8])
input('Gimme a number: ')
supose the code above is in Notebook1, if i open a new Notebook2 and from there run Notebook1 (%run Notebook1.ipynb), the first thing that pops is the input and the only thing that appears from the plot are the controls; the plot only appears after i make the input which is not good since i need to see the plot to make the correct input. I've tried with plt.show() with no results and if i use plt.draw() the plot is displayed but in non interactive mode so i can't make zoom or move through the data, this mode only activates after i make the input.
Anyone have any idea how to solve this?
Have you tried turning on the interactive mode using plt.ion() before sending the plot command?
Calling plt.gcf().canvas.draw() after plotting and before input worked for me.
Is it possible to plot pandas objects inside the PTVS interactive debugger? Is it possible to save plots to disk as jpeg's?
I think I was able to do this when I first started using PTVS (last year, its awesome by the way!) but I just tried again and I dont get any plots appearing. I cant remember if I had to do something special to get this to work and from doing some google searches I get a confusing picture of the current best practice in this regard.
I want to be able to plot diagrams from my debug interactive window, similar to what is shown on this pandas tutorial.
http://pandas.pydata.org/pandas-docs/stable/visualization.html
Is this possible?
Visual Studio Professional 2013 update 4 (latest I think)
PTVS 2.1.21008.00 (latest I think)
All help is greatly appreciated.
-Jason
[edit: more info on this http://pytools.codeplex.com/discussions/574776 ]
Unfortunately not. The regular interactive has an IPython mode that, among other things, enables inline plots. But the Debug interactive doesn't have that.
You can, of course, still load matplotlib in the Debug interactive and tell it to plot things. But because there's no integration of event loops between it and VS in that mode, the plots will basically work like modal windows - you won't be able to continue debugging or otherwise interact with VS until you close the plot window.
I have been working on some charts (like line chart, histogram, bar chart, pie chart, scattergram, radar chart, candle chart etc.) made in Java2D. I need to convert these charts into 3D charts without using Java3D API.
Is there any technique or algorithm available through which I may convert my 2D charts into 3D charts?
Or is anyone aware of any third party API (free or paid) available which can meet my requirement?
Any help or solution will be highly appreciable.
Thanks.
When you mention that you are creating plots and charts in Java2D, that implies that you are either creating these plots from scratch using your own coding or using ready made libraries such as jplot2d http://code.google.com/p/jplot2d/ or http://geosoft.no/graphics/. In either case, nothing will "convert" your Java2D charts to 3D charts. jzy3d jzy3d.org/ or TeeChart http://www.steema.com/teechart/java might do the job but will require to recode using their own APIs. Note that for pie charts and line charts, there is no point other than improving the look to go 3D. Only 3D data such as surfaces or contour plots need 3D.
Orson Charts is a 3D chart library for Java that renders using just the Java2D API. It's written by the author of JFreeChart (me), but it is not free - you can download an evaluation copy to try it out though.
You might have a look at Jzy3d.
It is free, open source, and easy to use.
There are tutorials to learn how to draw surface and scatter plots.
I generate a figure in MATLAB with large amount of elements (100000+) and want to save it into a PDF file. With zbuffer or painters renderer I've got very large and slowly opened file (over 4 Mb) - all points are in vector format. Using OpenGL renderer rasterize the figure in PDF, ok for the plot, but not good for text labels. The file size is about 150 Kb.
Try this simplified code, for example:
x=linspace(1,10,100000);
y=sin(x)+randn(size(x));
plot(x,y,'.')
set(gcf,'Renderer','zbuffer')
print -dpdf -r300 testpdf_zb
set(gcf,'Renderer','painters')
print -dpdf -r300 testpdf_pa
set(gcf,'Renderer','opengl')
print -dpdf -r300 testpdf_op
The actual figure is much more complex with several axes and different types of plots.
Is there a way to rasterize the figure, but keep text labels as vectors?
Another problem with OpenGL is that is does not work in terminal mode (-nosplash -nodesktop -nodisplay) under Mac OSX. Looks like OpenGL is not supported. I have to use terminal mode for automation. The MATLAB version I run is 2007b. Mac OSX server 10.4.
This is a funny one. Your problem is not Matlab, it's Ghostscript (Matlab creates PDFs by calling Ghostscript, at least on Windows). When I run
x=linspace(1,10,100000);
y=sin(x)+randn(size(x));
plot(x,y,'.')
print -dpsc2 test.ps
I've got a 2Mb PS file (all vector, of course), which when compressed became a 164Kb ZIP. One would expect to get more-or-less the same result when converting PS to PDF, but ps2pdf test.ps produced your 4Mb file!
Since you are on a Mac, you probably have Distiller. I'd give it a try — generate PS files as above, and then run them through Distiller; you should get a 150K vector PDF.
If you insist on rasterizing, I can suggest printing the figure without any axes or labels to a tiff, opening the tiff, and recreating axes and labels on top of it.
If you don't want to go with a 2D histogram (i.e. an image where pixel brightness corresponds to density of points) as BlessedKey suggests, it looks like the only good way is to do the rasterizing yourself, as mentioned by AB.
getframe followed by frame2im seems to be the way to go for that. Unfortunately, getframe returns empty if you run with -nodisplay. Therefore, you'd have to save the figure as .fig, and on another computer run a script that
opens the figure, gets the content of the axes with getframe, displays the image from getframe and then saves to pdf.
As an alternative to simple plotting or a 2D histogram, you may want to look into scattercloud, which combines plotting the points with density information, by the way.
If at all possible you should try to subsample your problem before building the illustration. If you are plotting points on a curve then 10,000 is probably more than you need. A modern printer is only about 600 DPI afterall.
If the points are illustrating a cloud with some density properties, a better solution may be to build a two dimensional histogram first, and illustrate that with imshow or imagesc.
If multiple clouds are being illustrated with different colors you may be interested in building one such image for each cloud and the combining them with transparency.