I want to save some Chaco plots to PDF (or another vector format such as EPS or SVG). I have already discovered PdfPlotGraphicsContext, but this suffers from two problems:
the PDF's page size is not adjusted to the size of the plot (requires a cropping post-processing step)
it doesn't seem to support transparency
Can these issues be worked around somehow, or is there an alternative way of exporting plots in a vector format?
Related
I have been a regular user of Matlab for plotting. I use matlabfrag to save figures as eps for the plot along with a tex file containing labels. The complete plot can be rendered in Latex upon calling the eps and tex files together.
Now that I switched to Python, I am wondering if there is any equivalent of matlabfrag for Python? I am aware of matplotlib2tikz but would like to avoid compute overload for generating plots each time on compiling Latex, as there are way too many plots sometimes.
PS: In the end, I am looking for plots with Latex-like fonts with a controllable font size. Reduced compute load is another requirement.
How can I save images generated with plotly in different formats? Only "Download as PNG" is possible from the generated HTML figure. I would need to interact with the figure (change rotation, choose which data to plot) and save an .eps figure for each online modified plot. Thanks a lot!
Plotly supports exporting to EPS (the docs mention that you need the poppler library) and the Figure object has a write_image method that saves a figure to a file.
You can specify the format through the filename and the resolution with the width and height keyword arguments, representing logical pixels.
You can read more on static image exporting in Plotly here. This is a code example:
fig.write_image("name.eps", width=1920, height=1080)
In order to select what is plotted you will have to set the figure's camera controls.
I have been reading a lot about Bokeh for visualisations of large datasets. I plan on plotting a heatmap with over 25 million points.
I saw read the page on speeding up WebGL and they mention that any plots with glyphs are accelerated.
Does the Heatmap plot use glyphs? Will there be any benefits in turning on WebGL for heatmap plots?
Pretty much everything that Bokeh draws is a glyph of some type. However, the text on that page you link actually states that "allows rendering some glyph types on graphics hardware." Currently (as of Bokeh 0.12.3) WebGL support only extends to scatter-type markers (e.g. circle, x, etc) and to lines. But HeatMap is implemented using the Rect glyph, so I would not expect WebGL to offer any improvement at the present time.
But I would add: It's good to thoroughly investigate any actual performance hotspots. Bokeh is really two libraries: a Python library and a JavaScript library. If you are seeing performance issues, are you sure it's on the JS side? For example, you have not said what your data sizes are. Are you sure it's not actually the binning/aggregation (that happens on the Python side) that is your issue?
Finally, if you have data sizes that are in the millions-to-billions of points range, you should probably be looking at the separate bokeh/datashader project.
I need to export pictures of the graphs and plots I am creating with Bokeh.
Usually I do
output_file("test.html")
However, I want to copy that graph into an Excel Sheet.
It does not have to be interactive anymore, though that would be brillant.
How do I export the graph as a picture? Using code, not clicking on "preview/save".
As of Bokeh 0.12.6, it is now possible to export PNG and SVG directly from
Python code.
Exporting PNGs looks like this
export_png(plot, filename="plot.png")
And exporting SVGs looks like this
plot.output_backend = "svg"
export_svgs(plot, filename="plot.svg")
There are some optional dependencies that need to be installed.
You can find more information in the Exporting Plots section of the User Guide.
Alternatively, if you are willing to work with JavaScript. And, for instance, if you want to save many canvas (each canvas element has a plot) at the same time you can use the JavaScript method canvas.toDataUrl() to convert the canvas to png as base64. When you get all the images you can do whatever you want with them. These images have 96dpi and it cannot be changed, so if you want more resolution you will have to update the sizes of all the elements of the plot before the convertion as well: fonts, axis, plot size...
If you use this approach you do not need to install selenium and phantomjs dependencies in your python environment.
Also, be aware that if you use export_png and you export the plot with a bigger size, the axis and fonts are not going to be proportionally bigger
I'm preparing a set of reports using open source ReportLab. The reports contain a number of charts. Everything works well so far.
I've been asked to take a (working) bar chart that shows two series of data and overlay a fitted curve for each series.
I can see how I could overlay a segmented line on the bar graph by creating both a line chart and bar chart in the same ReportLab drawing. I can't find any reference for fitted curves in ReportLab, however.
Does anyone have any insight into plotting a fitted curve to a series of data in ReportLab or, failing that, a suggestion about how to accomplish this task (I'm thinking that chart would need to be produced in matplotlib instead)?
I would recommend using MatPlotLib. This is exactly the sort of thing it's designed to handle and it will be much easier than trying to piece together something in ReportLab alone, especially since you'll have to do all the calculation of the line on your own and figure out the details of how to draw it in just the right place. MatPlotLib integrates easily with ReportLab; I've used the combination several times with great results.