-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify saving to PNG #2662
Comments
Related: #2453. |
So far my attempt at workaround is a #!/bin/sh
if [[ $# -eq 0 ]]
then
echo "No arguments were provided. Specify files to convert."
exit 1
fi
for file in "$@"
do
if [[ "$file" == *".html" ]]
then
in=`realpath $file`
out=${in/".html"/".png"}
/usr/bin/CutyCapt --url=file://$in --out=$out
echo "`basename $in` -> `basename $out`"
fi
done xclip -o > /usr/local/bin/htmltopng htmltopng dir_of_html_charts/* It seems CutyCapt can't parse an Altair html as the output is blank. Help needed. |
Thanks for documenting your approach. As you know now, to get html is easy, to get png is hard.. |
We've known the current approach is terrible for years, but the current approach is what we've found to be possible (and if I dare say, its better than nothing!) If you have ideas about technologies that could make it easier, we're all ears. |
No other suggestions apart from the potential solutions you referenced in #2453 and altair-viz/altair_saver#85. Why is it so straightforward for matplotlib and ggplot (plotnine)? Any ideas why my script isn't working? I'd be fine moving forward with that. |
Because their rendering stacks are built on codebases that can be distributed via wheels and executed natively on multiple platforms, whereas Altair's rendering stack is built on Javascript, which cannot be distributed via wheels and requires a browser process for execution. Further, because of very valid security concerns, browsers deliberately make it difficult to programmatically execute code in their runtimes.
I'm not familiar with CutyCapt, so no I don't have any ideas about what's going wrong. |
Thank you very much for explaining.
Are there any plans to address the issue at this level?
What is your workflow for getting out a png? |
No, I don't know of any plans to build a Vega-Lite renderer that does not depend on the Node/Javascript ecosystem.
I use the process documented here: https://altair-viz.github.io/user_guide/saving_charts.html#png-svg-and-pdf-format |
Thank you. Isn't that method broken as of altair-viz/altair_saver#104? |
Yes, the selenium version appears to be broken currently if you have a recent version of selenium installed. |
Okay full circle for me. Thanks for the help! |
Is there anyway to set the I couldn't find this parameter documented on the site. |
I have come up with a proof-of-concept for something that may be usable for this at the cost of distribution size and build complexity. But with the added benefit of no selenium or node just a TLDR: We compile |
Update: New release has some additional wheels (linux-glibc, win-x64, and macos-x64) folks can try locally, also fixed the issue with windows. |
Interesting @daylinmorgan! Thanks for working on this. |
I did some tests on my local machine (mac) and it worked out of the box. Nice! On Google Colab I noticed that text and labels are not captured in the saved png: https://colab.research.google.com/drive/1P__G39EAkoXDScR4AGtHi21u7z1uAXTu?usp=sharing 30mb for a rendering engine is not large! Small enough to be discussed to be integrated within Altair itself.. |
@daylinmorgan Big thanks for working on this! I don't know what would be regarded small/straightforward enough to be distributed with altair, but it is really exciting to see progress being made in this area! |
I think this is a much better workaround, if |
For anyone interested I've shifted work on this over to a separate package |
Thanks for the update @daylinmorgan! In fact, I already use |
Related tweet mentioning the possibility to for simplified vega-lite image export as part of a new vl convert package via deno https://twitter.com/jonmmease/status/1579529683900989440?s=20&t=uDxBGngqWXaaiaXjT9OdKw |
@joelostblom When starting to play around with this idea of embedding |
Hi all 👋 In case you're interested, here is a PR where I'm adding support for SVG and PNG export to VlConvert: vega/vl-convert#8. There's a lot in common with @daylinmorgan's okab approach (I'm also using resvg), but the architecture is fairly different given how VlConvert is using Deno embedded in Rust. I think I had a breakthrough in terms of how to get accurate SVG text placement without node canvas (overriding Vega's text width calculation function with a custom Rust function that computes the width using |
As of version 0.3.0, You can give it a try on Binder There's no specific integration with Altair right now, but I'd be happy to talk about what that could look like if the community finds that this approach works well for them. I'd also be happy to move the project to the Vega or Altair GitHub org if folks are interested in that. |
Vega probably makes more sense. If you give me admin permissions, I can move it. |
Sounds good! I sent you an invite and will make you an admin after you accept. |
The approach taken by Ideally |
Very much open for PRs to improve this experience! |
Thanks for the kind words on
This would be my preference, and I'd be happy to work on a PR for this soon |
This has been implemented in #2701 |
As a new user looking for better grammar and control than pandas and
matplotlib, this has been my adoption experience with Altair:
altair_saver
; install it.geckodriver
from package manager; install it.Problem is I need two dependencies for it to do something I would expect it to
support natively: save as PNG. These two dependencies are not able to be tracked
as dependencies as far as I know, meaning if I
pip uninstall altair
I'd likeit to take
altair_saver
andgeckodriver
with it. I would accept needing justaltair
andaltair_saver
from pip.Further, once I got the dependencies sorted, I had to search outside the
instructions to learn that if I'm using
geckodriver
I need to call save withsave(..., webdriver="firefox")
.Even after overcoming that, I got hit with an error due to a recent selenium
upgrade with breaking dependencies, as noted in this issue.
Sure if I'm making one plot, it's not too bad to output .html, view it in
firefox, and save to PNG using the dot menu. The problem is it's never just one
plot. I usually have a program that analyzes my dataframe and generates many
plots which I'd like to name then and there based on what I'm doing then and
there in the program.
A potential solution would be providing an Altair package or script, or linking
to an existing pip package that lets me output a directory of .html plots, and
convert them all to .png, preserving the basenames.
Best case scenario:
chart.save("to.png")
just works.I'm taking the time to write this to improve this otherwise powerful, promising
tool, and possibly, adoption thereof. I turned away from Altair simply because
the hurdle to save to PNG was disproportionately and unexpectedly large. I came
back because pandas and matplotlib is too restricting and indirect, and the
stifling of this became significantly clearer after my brief work with Altair.
It's worth noting I also tried plotnine in my search, and I found Altair's
documentation to be better, and syntax to be much more direct. Altair
had more pleasing default colors and conveniently used labeling from
the df, without intervention.
The text was updated successfully, but these errors were encountered: