<legend id='qn6fz'><style id='qn6fz'><dir id='qn6fz'><q id='qn6fz'></q></dir></style></legend>

      <tfoot id='qn6fz'></tfoot>
        <i id='qn6fz'><tr id='qn6fz'><dt id='qn6fz'><q id='qn6fz'><span id='qn6fz'><b id='qn6fz'><form id='qn6fz'><ins id='qn6fz'></ins><ul id='qn6fz'></ul><sub id='qn6fz'></sub></form><legend id='qn6fz'></legend><bdo id='qn6fz'><pre id='qn6fz'><center id='qn6fz'></center></pre></bdo></b><th id='qn6fz'></th></span></q></dt></tr></i><div id='qn6fz'><tfoot id='qn6fz'></tfoot><dl id='qn6fz'><fieldset id='qn6fz'></fieldset></dl></div>
      1. <small id='qn6fz'></small><noframes id='qn6fz'>

        • <bdo id='qn6fz'></bdo><ul id='qn6fz'></ul>

        如何将情节表达图保存到 html 或静态图像文件中?

        时间:2023-09-29
        <i id='t7Bhj'><tr id='t7Bhj'><dt id='t7Bhj'><q id='t7Bhj'><span id='t7Bhj'><b id='t7Bhj'><form id='t7Bhj'><ins id='t7Bhj'></ins><ul id='t7Bhj'></ul><sub id='t7Bhj'></sub></form><legend id='t7Bhj'></legend><bdo id='t7Bhj'><pre id='t7Bhj'><center id='t7Bhj'></center></pre></bdo></b><th id='t7Bhj'></th></span></q></dt></tr></i><div id='t7Bhj'><tfoot id='t7Bhj'></tfoot><dl id='t7Bhj'><fieldset id='t7Bhj'></fieldset></dl></div>

          <tbody id='t7Bhj'></tbody>

            <bdo id='t7Bhj'></bdo><ul id='t7Bhj'></ul>
              <tfoot id='t7Bhj'></tfoot>
              <legend id='t7Bhj'><style id='t7Bhj'><dir id='t7Bhj'><q id='t7Bhj'></q></dir></style></legend>
            1. <small id='t7Bhj'></small><noframes id='t7Bhj'>

                  本文介绍了如何将情节表达图保存到 html 或静态图像文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  但是,我觉得用 plotly.express 保存图形非常棘手.

                  如何将 plotly.express 或 plotly plot 保存到单独的 html 或静态图像文件中?有人可以帮忙吗?

                  解决方案

                  更新答案:

                  使用较新版本的 plotly,

                  文件夹中显示的文件:

                  从这里您可以在任何浏览器或任何其他您想要的方式中打开文件.

                  这是使用 Notepad++

                  显示的内容

                  如果您不介意一些体力劳动,您可以使用工具栏保存一个 .png 版本:


                  静态图片的旧答案:

                  自动生成静态图像有点有点棘手.

                  如果您愿意,请查看 Static Image Export in Pythonhtml.

                  我喜欢使用包括 orca 在内的方法,可以生成各种图像文件.除了使用 npm 安装它之外,我还没有找到任何其他方法来安装它 node.js 如果你按顺序得到它,你只需要运行以下命令来启动并运行它(我在 Windows 上):

                  npm install -g electron@1.8.4 orcapip install psutil 请求

                  然后你可以用 fig.write_image("C:/plotlyplots/lifeExp.png") 改变上面代码片段的最后一行,生成一个 .png文件.

                  However, I feel saving the figure with plotly.express is pretty tricky.

                  How to save plotly.express or plotly plot into a individual html or static image file? Anyone can help?

                  解决方案

                  Updated answer:

                  With newer versions of plotly, static Image export in Python is a breeze. Just make sure to install kaleido using:

                  pip install -U kaleido
                  

                  or, for Anaconda:

                  conda install -c conda-forge python-kaleido
                  

                  And then run

                  fig.write_image("yourfile.png") 
                  

                  Filetypes such as .jpeg and .pdf are also available options.

                  Producing an individual html file is still very easy:

                  Just use plotly.offline.plot(fig, filename='C:/plotlyplots/canada_offline.html')

                  This will give you a html file of a plotly express bar chart with the name lifeExp in a desired folder. Remember import plotly and not only import plotly.express as px.

                  Complete code:

                  # imports
                  import plotly
                  import plotly.express as px
                  
                  # data
                  df = px.data.gapminder().query("continent=='Oceania'")
                  
                  # plotly express bar chart
                  fig = px.line(df, x="year", y="lifeExp", color='country')
                  
                  # html file
                  plotly.offline.plot(fig, filename='C:/plotlyplots/lifeExp.html')
                  

                  Plot:

                  File as it appears in the foler:

                  From here you can open the file in any browser or any other way you want.

                  Here's the content as it is displayed using Notepad++

                  If you don't mind a bit of manual labor, you dan save a .png version using the toolbar:


                  Old answer for static images:

                  Producing a static image automatically is a bit mote tricky.

                  Take a look at Static Image Export in Python if you prefer that to html.

                  I like to use the approach including orca that can produce a variety of image files. I haven't found any other way to install it other than using npm which is installed with node.js If you get that in order, you only have to go run the following to get it up and running (I'm on Windows):

                  npm install -g electron@1.8.4 orca
                  
                  pip install psutil requests
                  

                  Then you can change the last line in the snippet above with fig.write_image("C:/plotlyplots/lifeExp.png") to produce a .png file.

                  这篇关于如何将情节表达图保存到 html 或静态图像文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图? 下一篇:情节:情节表达遵循什么颜色循环?

                  相关文章

                    <bdo id='CvCBu'></bdo><ul id='CvCBu'></ul>

                  1. <legend id='CvCBu'><style id='CvCBu'><dir id='CvCBu'><q id='CvCBu'></q></dir></style></legend>

                  2. <tfoot id='CvCBu'></tfoot>
                    <i id='CvCBu'><tr id='CvCBu'><dt id='CvCBu'><q id='CvCBu'><span id='CvCBu'><b id='CvCBu'><form id='CvCBu'><ins id='CvCBu'></ins><ul id='CvCBu'></ul><sub id='CvCBu'></sub></form><legend id='CvCBu'></legend><bdo id='CvCBu'><pre id='CvCBu'><center id='CvCBu'></center></pre></bdo></b><th id='CvCBu'></th></span></q></dt></tr></i><div id='CvCBu'><tfoot id='CvCBu'></tfoot><dl id='CvCBu'><fieldset id='CvCBu'></fieldset></dl></div>
                  3. <small id='CvCBu'></small><noframes id='CvCBu'>