You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h4id="New-to-Plotly?">New to Plotly?<aclass="anchor-link" href="#New-to-Plotly?">¶</a></h4><p>Plotly's Python library is free and open source! <ahref="https://plot.ly/python/getting-started/">Get started</a> by downloading the client and <ahref="https://plot.ly/python/getting-started/">reading the primer</a>.
22
+
<h4id="New-to-Plotly?">New to Plotly?<aclass="anchor-link" href="#New-to-Plotly?">¶</a></h4><p>Plotly's Python library is free and open source! <ahref="https://plot.ly/python/getting-started/">Get started</a> by downloading the client and <ahref="https://plot.ly/python/getting-started/">reading the primer</a>.
23
23
<br>You can set up Plotly to work in <ahref="https://plot.ly/python/getting-started/#initialization-for-online-plotting">online</a> or <ahref="https://plot.ly/python/getting-started/#initialization-for-offline-plotting">offline</a> mode, or in <ahref="https://plot.ly/python/getting-started/#start-plotting-online">jupyter notebooks</a>.
24
24
<br>We also have a quick-reference <ahref="https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf">cheatsheet</a> (new!) to help you get started!</p>
25
-
<h3id="Version-Check">Version Check<aclass="anchor-link" href="#Version-Check">¶</a></h3><p>Note: The static image export API is available in version <b>3.2.0.+</b><br></p>
25
+
<h3id="Version-Check">Version Check<aclass="anchor-link" href="#Version-Check">¶</a></h3><p>Note: The static image export API is available in version <b>3.2.0.+</b><br></p>
<h3id="Static-Image-Export">Static Image Export<aclass="anchor-link" href="#Static-Image-Export">¶</a></h3><p>New in version 3.2.0. It's now possible to programmatically export figures as high quality static images while fully offline.</p>
70
-
<h4id="Install-Dependencies">Install Dependencies<aclass="anchor-link" href="#Install-Dependencies">¶</a></h4><p>Static image generation requires the <ahref="https://github.com/plotly/orca">orca</a> commandline utility and the <ahref="https://github.com/giampaolo/psutil">psutil</a> Python library. There are 3 general approach to installing these dependencies.</p>
71
-
<h5id="conda">conda<aclass="anchor-link" href="#conda">¶</a></h5><p>Using the <ahref="https://conda.io/docs/">conda</a> package manager, you can install these dependencies in a single command:</p>
69
+
<h3id="Static-Image-Export">Static Image Export<aclass="anchor-link" href="#Static-Image-Export">¶</a></h3><p>New in version 3.2.0. It's now possible to programmatically export figures as high quality static images while fully offline.</p>
70
+
<h4id="Install-Dependencies">Install Dependencies<aclass="anchor-link" href="#Install-Dependencies">¶</a></h4><p>Static image generation requires the <ahref="https://github.com/plotly/orca">orca</a> commandline utility and the <ahref="https://github.com/giampaolo/psutil">psutil</a> Python library. There are 3 general approach to installing these dependencies.</p>
71
+
<h5id="conda">conda<aclass="anchor-link" href="#conda">¶</a></h5><p>Using the <ahref="https://conda.io/docs/">conda</a> package manager, you can install these dependencies in a single command:</p>
<p><strong>Note:</strong> Even if you don't want to use conda to manage your Python dependencies, it is still useful as a cross platform tool for managing native libraries and command-line utilities (e.g. git, wget, graphviz, boost, gcc, nodejs, cairo, etc.). For this use-case, start with <ahref="https://conda.io/miniconda.html">Miniconda</a> (~60MB) and tell the installer to add itself to your system <code>PATH</code>. Then run <code>conda install plotly-orca</code> and the orca executable will be available system wide.</p>
75
-
<h5id="npm-+-pip">npm + pip<aclass="anchor-link" href="#npm-+-pip">¶</a></h5><p>You can use the <ahref="https://www.npmjs.com/get-npm">npm</a> package manager to install <code>orca</code> (and its <code>electron</code> dependency), and then use pip to install <code>psutil</code>:</p>
75
+
<h5id="npm-+-pip">npm + pip<aclass="anchor-link" href="#npm-+-pip">¶</a></h5><p>You can use the <ahref="https://www.npmjs.com/get-npm">npm</a> package manager to install <code>orca</code> (and its <code>electron</code> dependency), and then use pip to install <code>psutil</code>:</p>
76
76
77
77
<pre><code>$ npm install -g electron@1.8.4 orca
78
78
$ pip install psutil</code></pre>
79
-
<h5id="Standalone-Binaries-+-pip">Standalone Binaries + pip<aclass="anchor-link" href="#Standalone-Binaries-+-pip">¶</a></h5><p>If you are unable to install conda or npm, you can install orca as a precompiled binary for your operating system. Follow the instructions in the orca <ahref="https://github.com/plotly/orca">README</a> to install orca and add it to your system <code>PATH</code>. Then use pip to install <code>psutil</code>.</p>
79
+
<h5id="Standalone-Binaries-+-pip">Standalone Binaries + pip<aclass="anchor-link" href="#Standalone-Binaries-+-pip">¶</a></h5><p>If you are unable to install conda or npm, you can install orca as a precompiled binary for your operating system. Follow the instructions in the orca <ahref="https://github.com/plotly/orca">README</a> to install orca and add it to your system <code>PATH</code>. Then use pip to install <code>psutil</code>.</p>
<h3id="Create-a-Figure">Create a Figure<aclass="anchor-link" href="#Create-a-Figure">¶</a></h3><p>Now let's create a simple scatter plot with 100 random points of variying color and size.</p>
90
+
<h3id="Create-a-Figure">Create a Figure<aclass="anchor-link" href="#Create-a-Figure">¶</a></h3><p>Now let's create a simple scatter plot with 100 random points of variying color and size.</p>
91
91
92
92
</div>
93
93
</div>
@@ -209,7 +209,7 @@ <h3 id="Create-a-Figure">Create a Figure<a class="anchor-link" href="#Create-a-F
<h3id="Write-Image-File">Write Image File<aclass="anchor-link" href="#Write-Image-File">¶</a></h3><p>The <code>plotly.io.write_image</code> function is used to write an image to a file or file-like python object.</p>
212
+
<h3id="Write-Image-File">Write Image File<aclass="anchor-link" href="#Write-Image-File">¶</a></h3><p>The <code>plotly.io.write_image</code> function is used to write an image to a file or file-like python object.</p>
213
213
<p>Let's first create an output directory to store our images</p>
<h3id="Get-Image-as-Bytes">Get Image as Bytes<aclass="anchor-link" href="#Get-Image-as-Bytes">¶</a></h3><p>The <code>plotly.io.to_image</code> function is used to return an image as a bytes object.</p>
402
+
<h3id="Get-Image-as-Bytes">Get Image as Bytes<aclass="anchor-link" href="#Get-Image-as-Bytes">¶</a></h3><p>The <code>plotly.io.to_image</code> function is used to return an image as a bytes object.</p>
403
403
<p>Let convert the figure to a <strong>PNG</strong> bytes object...</p>
<h4id="Display-Bytes-as-Image-Using-IPython.display.Image">Display Bytes as Image Using <code>IPython.display.Image</code><aclass="anchor-link" href="#Display-Bytes-as-Image-Using-IPython.display.Image">¶</a></h4><p>A bytes object representing a PNG image can be displayed directly in the notebook using the <code>IPython.display.Image</code> class. This also works in the <ahref="https://qtconsole.readthedocs.io/en/stable/">Qt Console for Jupyter</a>!</p>
467
+
<h4id="Display-Bytes-as-Image-Using-IPython.display.Image">Display Bytes as Image Using <code>IPython.display.Image</code><aclass="anchor-link" href="#Display-Bytes-as-Image-Using-IPython.display.Image">¶</a></h4><p>A bytes object representing a PNG image can be displayed directly in the notebook using the <code>IPython.display.Image</code> class. This also works in the <ahref="https://qtconsole.readthedocs.io/en/stable/">Qt Console for Jupyter</a>!</p>
468
468
469
469
</div>
470
470
</div>
@@ -509,7 +509,7 @@ <h4 id="Display-Bytes-as-Image-Using-IPython.display.Image">Display Bytes as Ima
<h3id="Change-Image-Dimensions-and-Scale">Change Image Dimensions and Scale<aclass="anchor-link" href="#Change-Image-Dimensions-and-Scale">¶</a></h3><p>In addition to the image format, the <code>to_image</code> and <code>write_image</code> functions provide arguments to specify the image <code>width</code> and <code>height</code> in logical pixels. They also provide a <code>scale</code> parameter that can be used to increase (<code>scale</code> > 1) or decrease (<code>scale</code> < 1) the physical resolution of the resulting image.</p>
512
+
<h3id="Change-Image-Dimensions-and-Scale">Change Image Dimensions and Scale<aclass="anchor-link" href="#Change-Image-Dimensions-and-Scale">¶</a></h3><p>In addition to the image format, the <code>to_image</code> and <code>write_image</code> functions provide arguments to specify the image <code>width</code> and <code>height</code> in logical pixels. They also provide a <code>scale</code> parameter that can be used to increase (<code>scale</code> > 1) or decrease (<code>scale</code> < 1) the physical resolution of the resulting image.</p>
513
513
514
514
</div>
515
515
</div>
@@ -554,7 +554,7 @@ <h3 id="Change-Image-Dimensions-and-Scale">Change Image Dimensions and Scale<a c
<h3id="Summary">Summary<aclass="anchor-link" href="#Summary">¶</a></h3><p>In summary, to export high-quality static images from plotly.py all you need to do is install orca and psutil and then use the <code>plotly.io.write_image</code> and <code>plotly.io.to_image</code> functions.</p>
557
+
<h3id="Summary">Summary<aclass="anchor-link" href="#Summary">¶</a></h3><p>In summary, to export high-quality static images from plotly.py all you need to do is install orca and psutil and then use the <code>plotly.io.write_image</code> and <code>plotly.io.to_image</code> functions.</p>
558
558
<p>If you want to know more about how the orca integration works, or if you need to troubleshoot an issue, please check out the <ahref="../orca-management/">Orca Management</a> section.</p>
Copy file name to clipboardExpand all lines: _posts/python/fundamentals/static-image/static-image-export.ipynb
+20-8Lines changed: 20 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,7 @@
48
48
"##### conda\n",
49
49
"Using the [conda](https://conda.io/docs/) package manager, you can install these dependencies in a single command:\n",
50
50
"```\n",
51
-
"$ conda install -c plotly-orca psutil\n",
51
+
"$ conda install -c plotly plotly-orca psutil\n",
52
52
"```\n",
53
53
"\n",
54
54
"**Note:** Even if you don't want to use conda to manage your Python dependencies, it is still useful as a cross platform tool for managing native libraries and command-line utilities (e.g. git, wget, graphviz, boost, gcc, nodejs, cairo, etc.). For this use-case, start with [Miniconda](https://conda.io/miniconda.html) (~60MB) and tell the installer to add itself to your system `PATH`. Then run `conda install plotly-orca` and the orca executable will be available system wide.\n",
" Cloning https://github.com/plotly/publisher.git to /private/var/folders/x2/smn4tpcs0s1ft0gg294_fq7h0000gn/T/pip-req-build-_rjlen\n",
892
+
" Cloning https://github.com/plotly/publisher.git to /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-req-build-Imdlya\n",
893
893
"Building wheels for collected packages: publisher\n",
894
894
" Running setup.py bdist_wheel for publisher ... \u001b[?25ldone\n",
895
-
"\u001b[?25h Stored in directory: /private/var/folders/x2/smn4tpcs0s1ft0gg294_fq7h0000gn/T/pip-ephem-wheel-cache-5WnI5R/wheels/99/3e/a0/fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n",
895
+
"\u001b[?25h Stored in directory: /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-ephem-wheel-cache-K1Olar/wheels/99/3e/a0/fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n",
896
896
"Successfully built publisher\n",
897
897
"Installing collected packages: publisher\n",
898
898
" Found existing installation: publisher 0.11\n",
899
899
" Uninstalling publisher-0.11:\n",
900
900
" Successfully uninstalled publisher-0.11\n",
901
-
"Successfully installed publisher-0.11\n",
902
-
"\u001b[33mYou are using pip version 10.0.1, however version 18.0 is available.\n",
903
-
"You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n"
0 commit comments