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, ...)
Related
Is there any way in Python to modify the source data by moving data points in the chart?
This is intended to work in streamlit: I'd like to make it convenient for users to edit multiple parameters of the same kind visually changing the curve which represents series of parameters and their corresponding value. As far as I know, streamlit currently supports Matplotlib, Plotly, Altair, Bokeh, Vega Lite, Deck.GL, dagre-d3 charts, but not sure whether any of those libraries provide this functionality.
Pandas has two nice functionalities I use a lot - that's the df.style... option and the df.to_latex() call. But I do not know how to combine both.
The .style option makes looking at tables much more pleasant. It lets you grasp information rapidly because of visual enhancements. This works perfectly in a jupyter notebook, for example. Here is an arbitrary example I copied from the documentation.
df.style.bar(subset=['A', 'B'], align='mid', color=['#d65f5f', '#5fba7d'])
This yields:
However, as nice as this looks in a jupyter notebook, I can not put this to latex code. I get the following error message instead, if chaining a 'to_latex()' call at the end of my visual enhancements: AttributeError: 'Styler' object has no attribute. Does that mean it's simply not possible, because the displayed colorful table is not a DataFrame object any more, but now a Styler object, now?
Is there any workaround? At least with easier tables, let's say where only cells have a single background color with respect to their value, instead of a 'complicated' bar graph.
As of pandas v1.3.0 these are now combined in pandas.io.formats.style.Styler.to_latex.
Instead of trying to export this formatting to bulky LaTeX markup, I would go the route explored already over in TeX.SE: add the functionality as LaTeX code that draws similar formatting based on the same data.
Red/green value bars:
Partially coloring cell background with histograms
Coloured cell backgrounds:
Are there an easy way to coloring tables depending on the value in each cell?
Shaded backgrounds (similar, but points to excellent package pgfplotstable):
Parametrize shading in table through TikZ
I don't know how you can use latex directly but you can use df.to_html(). Once you get the html you can style it as you like and then use any of the following.
Python's html2latex
Website :HTML to TEX Converter
Python's weasyprint
Pandoc
Here is one latex package that I found on googling that talks about embedding html in latex.
https://alvinalexander.com/blog/post/latex/use-html-package-in-latex-control-your-output/
I once only used latex and embedded images of tables when I used it.
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).
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 large data set of tuples containing (time of event, latitude, longitude) that I need to visualize. I was hoping to generate a 'movie'-like xy-plot, but was wondering if anyone has a better idea or if there is an easy way to do this in Python?
Thanks in advance for the help,
--Leo
get matplotlib
The easiest option is matplotlib. Two particular solutions that might work for you are:
1) You can generate a series of plots, each a snapshot at a given time. These can either be displayed as a dynamic plot in matplotlib, where the axes stay the same and the data moves around; or you can save the series of plots to separate files and later combine them to make a movie (using a separate application). There a number of examples in the official examples for doing these things.
2) A simple scatter plot, where the colors of the circles changes with time might work well for your data. This is super easy. See this, for example, which produces this figure
alt text http://matplotlib.sourceforge.net/plot_directive/mpl_examples/pylab_examples/ellipse_collection.hires.png
I'd try rpy. All the power of R, from within python.
http://rpy.sourceforge.net/
rpy is awesome.
Check out the CRAN library for animations,
http://cran.r-project.org/web/packages/animation/index.html
Of course, you have to learn a bit about R to do this, but if you're planning to do this kind of thing routinely in future it will be well worth your while to learn.
If you are interested in scientific plotting using Python then have a look at Mlab: http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html
It allows you to plot 2d / 3d and animate your data and the quality of the charts is really high.
Enthought's Chaco is designed for interactive/updating plots. the api and such takes a little while to get use to, but once you're there it's a fantastic framework to work with.
I have had reasonable success with Python applications generating SVG with animation features embedded, but this was with a smaller set of elements than what you probably have. For example, if your data is about a seismic event, show a circle that shows up when the event happened and grows in size matching the magnitude of the event. A moving indicator over a timeline is really simple to add.
Kaleidoscope (Opera, others maybe, Safari not) shows lots of pieces moving around and I found inspirational. Lots of other good SVG tutorial content on the site too.
You might want to look at PyQwt. It's a plotting library which works with Qt/PyQt.
Several of the PyQwt examples (in the qt4examples directory) show how to create "moving" / dynamically changing plots -- look at CPUplot.py, MapDemo.py, DataDemo.py.