I am using Python's scientific plotting library matplotlib. I am trying to use matplotlib to show an image using imshow. I would like to be able to adjust the color range with in the figure with some type of UI. From what I can tell, there isn't a built-in way to do this in matplotlib, and I have found much on this issue. This is a fairly common use-case and easy to do in MATLAB. How does one do this in matplotlib?
I'm assuming you want to change the cmap attribute. You could use the built-in function input to read some new value from the command line (not really a GUI) or you could use the matplotlib.widgets package which includes e.g. a slider and buttons (see this link for examples).
Related
Usually, we use the line to plot graphs and confusion matrices. However, the official documentation doesn't really specify which types of figures are supported.
Can I actually use it for image files?
(I tried using it but it doesn't run properly, I don't know whether it was because of it not supporting it)
Based on the documentation, it supports a fig meaning a plotly figure object.
Unless you create a plotly figure object containing your image, you won't be able to use plotly.io.write_html(fig, ...)
I am interested in porting some of my old fractal imaging programs over from Borland C to python. In Borland C, the putpixel command would place a specified color pixel within a rasterized graphical field. Is there a simple way to do this in matplotlib?
So the answer depends on what you're trying to do here. matplotlib has a lot of utilities for working with representing image data, this might give a good starting point for getting familiar with matplotlib's workflow. You can directly edit the values of the numpy array that you're using matplotlib to visualize, but matplotlib doesn't give you access to the data that you're rendering.
I imagine that you already have written some colormap and other rendering tools tools, but to get an idea of what matplotlib might have built in, I recommend looking at this example. It's a simple Mandelbrot, escape time, but it makes use of nonlinear colormapping and shading.
In my experience, I've normally computed the fractal as a 2D numpy array, and then allowed matplotlib to handle the coloring, and scaling of the final output image. Matplotlib doesn't work like the canvas experience it sounds like you're used to using. I'd recommend filling a numpy array with the desired pixel values as you've computed them, and then sending that array off to matplotlib to be rendered.
After posting this I discovered that there is a putpixel command in PIL (Python Imaging Library), which has tools for dealing with pixel oriented graphics. Matplotlib can also do the job as suggested by the answer above.
I am looking to replace a MATLAB GUI used to do manual scoring of objects within a tif file. Someone recommended Bokeh to me. Is it possible to read a tif-file using any module and allow interactivity via Bokeh?
I have not used Bokeh (but I have kept an eye on it), so my answer is: Yes, you could probably use Bokeh for this.
But considering that you are replacing a MATLAB GUI, I think there might be an easier way. Bokeh creates plots that run in your web browser, which might not be what you want.
Instead, you could look into using matplotlib to do it.
The PyPlot API in matplotlib is very similar to the plot functions in MATLAB, and it supports creating interactive plots.
To read the TIFF file I would recommend looking into either PIL or OpenCV.
I have a code for plotting 3d scatterplot in python that updates after every 2 seconds (plot is dynamic). I wish to be able to adjust the values of some of the parameters on line (while plotting happens) based on which the plotting happens. Is it possible to give a textbox along with the plot from which we can take as input the required parameter value based on which this plot will then be subsequently modified?
Matplotlib does not have a textbox (or other text entry) widget. To use a textbox, you would need to embed a matplotlib graph within a separate GUI framework. To do this, decide on the GUI framework you want to use (qt, wx, gtk, or tkinter), and a textbox widget from the gui framework, and then add the plot from matplotlib. This isn't difficult and there are lots of available examples, generally best found for each specific framework you're interested in.
There might also be other pure matplotlib approaches that could work for you, such as using a matplotlib slider widget, or you could directly capture keyboard events, but without knowing exactly what you're going to for, it's hard to say.
does anyone know if it's possible to generate such plots in matplotlib?
the image is taken from the following page. If not, there another 'python' solution to generate such plots?
You want to use the packange networkx which will take care of the layout and plotting (via matplotlib if you want).