简体   繁体   中英

Unable to export an Altair Plot directly to .png

I'm currently unable to save an Altair plot I've produced as a .png . I'm trying to export the plot as an image so that I can embed it directly into an outlook email. The two methods I've tried are:

  1. Using built-in alt.chart.save() with an embed_option of 'renderer' as png :

    ((hours & oilp & wear & viscos & chart).resolve_scale(x='shared', color='independent')& (bars)).save("Chart.png", embed_options={'renderer':'png'})

  2. Using altair_saver.save() with the .png extension:

    altair_saver.save(((hours & oilp & wear & viscos & chart).resolve_scale(x='shared', color='independent') & (bars)),"Chart.png")

I've followed this link and installed selenium and chromedriver using the anaconda cmd as it appears to interpret the Vega-lite extension in a browser then export in the form of an image.

The error I receive is as below:

C:\Users\\Anaconda3\lib\site-packages\altair_saver\_core.py in _select_saver(method, mode, fmt, fp)
     67     else:
     68         raise ValueError(f"Unrecognized method: {method}")
---> 69 
     70     spec: JSONDict = {}
     71     if isinstance(chart, dict):

ValueError: No enabled saver found that supports format='png'

Has anyone had any experience with this error or may be to provide a solution?

Also is it possible to embed a vega HTML output directly into the body of an Outlook email with full hover over functionality? I anticipate that Outlook will not be equipped with the necessary rendering capabilities.

我遇到了这个问题,问题是我需要更新我的 chromedriver 版本以匹配我的 Chrome 版本。

If you expect to be saving charts with chromedriver, the error you are seeing indicates that a selenium chromedriver instance cannot be instantiated. You can try to do this directly using the following:

import selenium.webdriver
driver = selenium.webdriver.Chrome()

Make certain selenium, chromedriver, and Google Chrome are all properly installed on your system, and then PNG output should work. Note that conda cannot install Google Chrome for you, nor can it ensure that the version of chromedriver is compatible with the version of Google Chrome that you have on your system.

You can find the full set of installation instructions in the altair_saver documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM