I have been working with IPython for several months now and I think it is one of the best interactive shells I've used. I especially like the built in matplotlib support through pylab.
One issue I have had is that I am working with image analysis and often plot images and other arrays using imshow. When using pure matplotlib, I have the ability to set the default interpolation as nearest using the matplotlibrc file. I have not been able to find such a file for the built in matplotlib in IPython.
Is there a way to configure IPython and Pylab to use nearest interpolation by default instead of bilinear? I have read the IPython documentation regarding configuration and customization and I'm not sure I follow how to access such specific properties.
Related
Is there a way to turn a matplotlib.pyplot plot into a Flowable object within reportlab so that I can render it within a pdf?
My question is very similar to the question asked here. However, I am limited because I am working on a system where I can only use a certain set of libraries. These are:
The libraries installed with Anaconda 2
reportlab
Is this possible with the set of packages that I have?
EDIT: I would like to avoid saving the plot as a png
Is there any python libs that could calculate poles of a line like [(x1,y1), (x2,y2)...]?
for instance, I have a line consist by 2d points like [[x1,y1],[x2,y2],[x3,y3]...], then I want to calculate the poles of the line, only using python libs. So is there any python lib could do this for me
Hello HOWE,
Python provides many library for the create the any types of the graph.
For example 2d, 3d,... graph etc.
1. NumPy
If you use Math function/expression so first install this library it is provides many easy functionality.
NumPy is the fundamental package for scientific computing with Python. It contains among other things:
a powerful N-dimensional array object
sophisticated (broadcasting) functions
tools for integrating C/C++ and Fortran code
useful linear
algebra, Fourier transform, and random number capabilities
Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of generic data. Arbitrary data-types can be defined. This allows NumPy to seamlessly and speedily integrate with a wide variety of databases.
Install this library for go on this link, http://www.numpy.org/
2. Matplotlib
After install this library to create the any types of the graph.
Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib can be used in Python scripts, the Python and IPython shell, the jupyter notebook, web application servers, and four graphical user interface toolkits.
Install this library for go on this link, https://matplotlib.org/
I hope my answer is helpful.
If any query so comment please.
I have used customization using css and other scripts for matplotlib graphs on ipython notebooks. Can I use the customization scripts for the code being run on terminal? How?
Matplotlib allows customizations using so called rcParams. The documentation is pretty easily accessible:
http://matplotlib.org/users/customizing.html
I have a Python script that generates an interactive matplotlib plot with several sliders and radio buttons using the matplotlib.widgets submodule. I'd like to let others play with the resulting plot without having to install python, scipy, numpy, and matplotlib.
I first tried converting my python script to a stand-alone executable that I could distribute. This turned out to be a nightmare - every package I tried (pyinstaller, py2exe, cx_Freeze) failed for one reason or another. The main issue I had was with integrating various scipy and matplotlib libraries, and I'm now very pessimistic about successfully "freezing" my interactive plot.
My next idea was to see if I could get some interactivity through a web browser. Using an IPython notebook with the third-party package JSAnimation initially seemed very promising (http://nbviewer.ipython.org/github/jakevdp/JSAnimation/blob/master/animation_example.ipynb), but it seems that the package only supports the matplotlib "animate" function. This doesn't quite fit the bill for what I'd like to do, as I have multiple sliders which 1) doesn't seem to be supported by this package, and 2) even if supported, would likely result in too many static figures to pre-render effectively, since any such arrangement would require snapshots for every possible combination of the three variables.
Any ideas for how to get this interactive matplotlib plot to others without requiring them to install Python?
I currently have a GUI built in wxPython with several sections, one of which displays a .png image of a plot:
self.plot = wx.BitmapButton(self.pane_system, -1, wx.Bitmap("/home/myname/projects/newton/plot/src/graph.png", wx.BITMAP_TYPE_ANY))
In another part of the GUI, there is a place where I can edit parameters. The current setup is that When I change the parameters and press enter, the code tells Gnuplot to re-plot and save the new plot to the graph.png file, then update the GUI to show the updated image.
I have several general questions:
I want to migrate gnuplot to matplotlib for the following reason: If I use gnuplot, the machine that is running the executable must have gnuplot installed on their machine. On the other hand, matplotlib is a python module, so I don't have to worry about installing graphical packages on the other machines. Is this assumption correct?
How can I modify my wxPython GUI window to show the matplotlib plot? I found tutorials several telling me how to create a new panel with a matplotlib plot, but I would like to simply have it appear where the old plot was. I think I can make matplotlib save the plot to an image file just as I did in gnuplot. Is it generally a good idea to save the plot as an image and update the GUI, or are there other (faster) best practices for updating plots? One drawback of using image files (as in the above code) is that they do not resize when I resize the GUI window.
If I package this as an executable, will I have to install wxPython/Python on a Windows machine to make the executable run?
Taking your questions in order:
1.) Yes matplotlib is a contained python module. It does have external dependancies but in Windows these dependencies are packaged with the matplotlib install. Do you need to worry about these when you install on other machines? That depends on how you are going to install. Are you packing to an exe? Having the end users install Python and matplotlib? As an example you can package matplotlib into your exe with py2exe, see here. Of course you'll have to customize those scripts for your backend, wx.
2.) You are seeing the panels with plots because matplotlib provides the FigureCanvasWxAgg, which is a wxWidget derived from wxPanel that plays nice with matplotlib. The advantages of using it are that you can set handlers for stuff like resize and painting.
Your wxBitMapButton, though is looking for a wxBitmap for the image. You might be able to give it a file handle (cStringIO.StringIO) to a matplotlib plot and eliminate the need to write a file to disk. You also could probably hook it's resize event and get matplotlib to redraw the figure to the appropriate size. You aren't going to have the amount of flexibility as using the FigureCanvasWxAgg. I can't research any of this, though, as it seems the wxPython web-site is down.
3.) You can package wxPython into executable. How depends on what packager you are using. I've done this with py2exe many times.