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.
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, ...)
Is there a way to insert a picture inside a cell using pptx python?
I'm also thinking of finding the coordinate of the cell and adjust the numbers for inserting the picture, but can not find anything.
Thank you.
No, unfortunately not. Note that this is not a limitation of python-pptx, it is a limitation of PowerPoint in general. Only text can be placed in a table cell.
There is nothing stopping you from placing a picture shape above (in z-order) a table cell, which will look like the picture is inside. This is a common approach but unfortunately is somewhat brittle. In particular, the row height is not automatically adjusted to "fit" the picture and changes in the content of cells in prior rows can cause lower rows to "move down" and no longer be aligned with the picture. So this approach has some drawbacks.
Another possible approach is to use a picture as the background for a cell (like you might use colored shading or a texture). There is no API support for this in python-pptx and it's not without its own problems, but might be an approach worth considering.
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 recently downloaded itrade, and so far I have been unable to get it to run (dependency on wxaddons amongst other things). Also, the project seems to have been disbanded since 2008.
Last but not the least, the project contains a lot of functionality which I just don't need.
All I require is the functionality to produce a graph similar to that shown on the Journalier tab in the image below; and to be honest, I don't even need all of the additional indicators shown in the image. I will be happy enough with the (1st) top chart and the (2nd) midle sub chart, without all the indicators.
I have had a look at the code, and since I am not familiar with wxPython etc, I am finding it difficult to locate the code that is responsible for producing the image below.
I'd be grateful if anyone with either wxPython or itrade experience could outline the steps needed (or explicitly state how) to extract only the section of the code that produces the image below. The objective being that I can read in data from a CSV file, and pass it to the new script, to display a GUI plot similar to the one shown below.
If you really have to do this, this would be my approach:
Find the code that produces these tabs
Find the code that produces the visual graph for the Journalier tab
Find the code where the data is produced that is displayed in the graph
Find the code that passes the data to the graph and how it is processed before being displayed
Extract the necessary pieces of logic to produce and process the data
Use a plotting library to create the graph; it's easier to hook a plotting library into your application than to try and integrate this particular piece of visual code. Especially if you don't need most of the visual indicators.
I need to create a GUI for graph construction ("graph" as an abstract representation of a set of objects, not a visual representation of data). The interface will provide a choice of ~5 vertex types and of ~5 edge types. Each vertex will have two data fields: a text label and a file name, which need to be easily editable.
I'm familiar with igraph and have a lot of code written in it. I will use igraph to manipulate the graphs created with this GUI.
Since this will be my first GUI, I'm completely ignorant of what tools are available. Can you please suggest a free library, knowing that eventually the program will need to work on Windows?
EDIT
it seems from the answers I get that I wasn't clear enough. I'm not looking for a way to visualize a graph, but rather for a way to visually create one. By visually, I mean not needing to manually create text files or writing code.
Take a look at xdot.py.
From the homepage
xdot.py is an interactive viewer for graphs written in Graphviz's
dot language.
It uses internally the graphviz's xdot output format as an
intermediate format, and PyGTK and Cairo for rendering.
xdot.py can be used either as a standalone application from
command line, or as a library embedded in your python application.
I like networkx,
from networkx import draw, Graph
from pylab import show
g = Graph()
g.add_edges_from([(1,2),(1,3),(2,4),(2,5)])
draw(g)
show()
which gives,
The only quirk is the requirement for matplotlib to get builtin plotting to work.
If you use python, I think PyQt is a good selection.
What you have to install is listed below:
install Python from here
install PyQt4 from here
But it takes many lines to write GUI application,
it is sometimes better to generate an image to display with image viewer.