Writing a table to a matplotlib pdf file - python

I am using matplotlib and a modified version of this example to generate plots in pdf files. So I am plotting each plot on a single page and the results are just fine.
Now I would like to list all the data used in the plots in a rather long table. This table should be placed below the last plot (so not each plot should get its own table).
Is there a way to plot LaTeX like tables in a pdf file using matplotlib?

In principle, you can place almost any TeX stuff onto a plot using something like plt.text(1,2,r'$a^2+b^2=42$'). For aligning equations things like eqnarray work as well, like this. Just don't forget to use raw strings, for otherwise python can misinterpret TeX commands which start with backslashes.

Unless using a plot to write text, I think it is save to say, that it is not possible to only write a table to a matplotlib pdf output file.
Currently I am using tex to write the table and pyPdf to merge the two results. I think this is the cleanest solution to the problem.

Related

Exporting functional Plotly sunburst plot

Does anyone know how I can export a plotly sunburst plot as a standalone file which can keep all the functionalities, like annotation while hovering and expansion by click?
Visualizing a hierarchical data with plotly.sunburst in python is a beautiful and beneficial way of presenting it in the best order, while you are able to hover the values to see the annotation, click on each parent section to collapse and expand the child values, etc.. But to present the visualized data (plot) independently without having to open the Python notebook, needs the plot to be saved and exported in a standalone file format that allows keeping every functionality available.
Does anyone know how to do this? and what file format can give this luxury to us?
Thanks
Saving to an HTML file will do the trick:
doc

How to export plotly plots, tabs and images into a single html

I would like to know if there is a way to export multiple plotly plots, tabs and images into a single HTML file.
In detail the problem is this. I want to create a standalone .exe file with python able to plot several graphs and images, given some input files containing the data; writing code with PySimpleGUI for the GUI.
But once the several interactive graphs, tabs and images are plotted in a window, I would like to add in the window two buttons to export these data respectively in a excel file (so with no interactivity) and in a HTML file (to keep interactivity).
The first point is no trouble for me: I use xlsxwriter to export images and graphs as images. The problem is the second point: I would like to export all these data keeping interactions in graphs in a single HTML with a certain design I choose. Remember the fact that I want to build a standalone .exe file, because this program will run in a PC with Python not installed.
My question is this: is there some python library or html writer in python I can use to do this?
P.S.: plotly graphs are not subplots of a single plots but each one is a single plot, each one will have its own zoom etc. commands.

Is there any way to save all graphs generated using the script to a single file (image preferably)

The scripts I use generate a lot of graphs. I was wondering if there was a way to save them or specified ones into a single file as image or pdf for quicklooks.
Thank you.
If you are using matplotlib, it would be easiest to use the subplots feature. This will make all of your graphs part of a single object, which can be saved as an image like you want. I would redirect you to the matplotlib website for a ton of good example on the subject. https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.subplots.html
Then, do
fig.savefig('mysweetsubplots.png')
and you are done.

Generating Reports with Python: PDF or HTML to PDF

Using maptplotlib I have created 9 graphs which are combined in to a single pdf using the command savefig. However I need to be able to show the statistical analysis below each plot with .describe(). What would be the best way to do this?
Pandas has the possibility to include a table with a plot. See the table kwarg to pandas.DataFrame.plot. See the docs: http://pandas.pydata.org/pandas-docs/dev/visualization.html#visualization-table
There are multiple possibilities:
http://pbpython.com/pdf-reports.html
http://gael-varoquaux.info/computers/pyreport/
https://github.com/JanSchulz/knitpy
For the last, have a look at https://github.com/JanSchulz/knitpy/tree/master/examples, the docx, pdf and html versions were generated from the .pymd source. The example includes both pandas.DataFrames and matplotlib figures.
Disclaimer: I'm the author of knitpy

how to create a bar chart with matplotlib using table data

The idea is quite simple: I want to create a bar chart with matplotlib using data of a table that is being generated before.
I expect a chart like this one:
http://matplotlib.sourceforge.net/examples/pylab_examples/table_demo.html
But Im wondering how to do this just by using data out of a dbf table instead.
It seems to be somehow possible but even this example I didn't get to work:
http://www.packtpub.com/article/plotting-data-using-matplotlib-part2?utm_source=js_matplotlib_abr3_1009&utm_medium=content&utm_campaign=janice
As I am a beginner with matplotlib I would like to learn this using a functioning example.
1) Are there any examples or code snipplets around to look at that any of you could recommend?
2) What data format would be best for this task (my tool generates dbf, but it's probably not a big deal to convert either to csv or Excel)
There is dbfpy which allows you reading from a DBF file. But I suggest using a CSV file and numpy.loadtxt if possible, because it should be much faster.

Categories