{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### New to Plotly?\n",
"Plotly's Python library is free and open source! [Get started](https://plotly.com/python/getting-started/) by downloading the client and [reading the primer](https://plotly.com/python/getting-started/).\n",
"
You can set up Plotly to work in [online](https://plotly.com/python/getting-started/#initialization-for-online-plotting) or [offline](https://plotly.com/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plotly.com/python/getting-started/#start-plotting-online).\n",
"
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!\n",
"\n",
"### Version Check\n",
"Note: The static image export API is available in version 3.2.0.+
"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'3.2.0'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly\n",
"import plotly.graph_objs as go\n",
"from plotly.offline import iplot, init_notebook_mode\n",
"\n",
"plotly.__version__"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Overview\n",
"This section covers the lower-level details of how plotly.py uses orca to perform static image generation. Please refer to the [Static Image Export](../static-image-export/) section for general information on creating static images from plotly.py figures.\n",
"\n",
"### What is Orca?\n",
"Orca is an [Electron](https://electronjs.org/) application that inputs plotly figure specifications and converts them into static images. Orca can run as a command-line utility or as a long-running server process. In order to provide the fastest possible image export experience, plotly.py launches orca in server mode, and communicates with it over a local port. See https://github.com/plotly/orca for more information.\n",
"\n",
"By default, plotly.py launches the orca server process the first time an image export operation is performed, and then leaves it running until the main Python process exits. Because of this, the first image export operation in an interactive session will typically take a couple of seconds, but then all subsequent export operations will be significantly faster, since the server is already running."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create a Figure\n",
"Now let's create a simple scatter plot with 100 random points of variying color and size."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import plotly.graph_objs as go\n",
"import plotly.io as pio\n",
"\n",
"import os\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We'll configure the notebook for use in [offline](https://plotly.com/python/getting-started/#initialization-for-offline-plotting) mode"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/vnd.plotly.v1+html": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"init_notebook_mode(connected=True)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"data": [
{
"marker": {
"color": [
0.4742011944160235,
0.23178283722750537,
0.8271397810237594,
0.44879630893471023,
0.1269012823466693,
0.9136971076757464,
0.04406177368155906,
0.7400660836945993,
0.5043337261546271,
0.44726182321902697,
0.6920749109941943,
0.5648169690598706,
0.7732514180268509,
0.7600753368607004,
0.83266561962631,
0.24905816885385235,
0.951832368744788,
0.1988088321378827,
0.38259385462556306,
0.5729509416793358,
0.043954917932159,
0.9818522852430921,
0.6970357584126924,
0.07668338222220838,
0.9098861457036148,
0.6881780206548511,
0.26743043728661153,
0.007442205726257534,
0.9011729314736598,
0.5703769955259455,
0.06054591978522683,
0.23838904420279816,
0.19706091534603842,
0.9001524640447744,
0.2177975839566244,
0.3451481890995187,
0.6101829308931076,
0.010977446905593435,
0.18355961380672048,
0.9443877078300453,
0.5271249206647258,
0.19381554967211867,
0.6533404583547884,
0.8083755099908582,
0.24953203568718751,
0.05430631384630724,
0.2567162253451978,
0.16449975168793451,
0.3854698042408021,
0.3744703025402253,
0.9821128030519019,
0.14357603140179775,
0.3115166196707917,
0.5091137961581611,
0.6097037911978269,
0.6043024524480158,
0.6836901558772435,
0.9656583748172867,
0.09311205833066483,
0.8594011350631228,
0.24573787609372477,
0.7770459598833492,
0.6974756619499469,
0.8181040276066682,
0.27548553254222685,
0.8738260250075238,
0.044776868302611184,
0.8694871625997395,
0.9570784027207536,
0.0015774853778565134,
0.9118606494149065,
0.21177549438845522,
0.09201597078154145,
0.5298058163561132,
0.8390242216621389,
0.23429812331120115,
0.02827513457122033,
0.42065852673770254,
0.6637372322661272,
0.5329486592550877,
0.015382562774523767,
0.37966585307735445,
0.3209448578467017,
0.6939124110708672,
0.519735277702955,
0.26455075995227784,
0.8183988665175638,
0.48667191903463847,
0.6672915609634664,
0.14259843571128084,
0.18411390996597954,
0.6149481082625393,
0.04562257249594226,
0.25862804441746745,
0.05923756169278693,
0.9309356909057983,
0.5011022680655863,
0.7158407254534417,
0.7734231191513281,
0.2424413118288744
],
"colorscale": "Viridis",
"opacity": 0.6,
"size": [
13.355596966212188,
1.256608956941564,
18.51153175077881,
23.524982970840206,
22.00276281629357,
12.64075772099369,
21.39510944277142,
20.483857333297337,
28.819701170233458,
14.539124434144679,
13.233702680158322,
2.030500796146365,
6.462640562807081,
19.034784400544527,
3.385805782952902,
16.939920127452577,
14.191588027596104,
3.1711876815465443,
15.53735117422184,
26.874529788769895,
2.3821665185428986,
25.274251386468038,
0.23445746055849814,
25.244569781815752,
9.902239001950456,
11.71838742264634,
21.137749154032083,
6.459211597717928,
19.21910636195498,
4.017672961047495,
1.0946323410907022,
27.578603188067977,
19.36519424524754,
27.510321501156383,
26.546775273357383,
25.299104527109456,
21.25928674018767,
5.775487363049484,
7.071146951140463,
11.42849737381548,
13.931606284388964,
14.578689416727336,
29.39879320294038,
23.567270631001602,
23.403981600208535,
3.222100790587421,
13.754245721568653,
18.174740593585057,
23.275226425498545,
29.389352231344677,
9.16072385409645,
15.343806501915774,
0.5606189273464057,
25.739083167283937,
23.95552381409849,
29.89938017412855,
22.483793604940626,
26.348092070224276,
23.579216465573964,
21.470156245568074,
12.2726236705932,
6.098746490833019,
18.444812175121104,
7.3973502522567625,
9.361073268805555,
25.063818225648934,
14.919976885381189,
21.48502014942277,
2.013287575032525,
21.959190159072836,
21.53850069931638,
10.765305280868887,
22.239375964156494,
1.8670740009976372,
14.09480450096702,
27.779924606453477,
27.283429605322695,
11.688434840601884,
14.874559265685752,
27.589569320287353,
18.58630085726821,
15.343657243513356,
28.33036098848515,
6.210582598821638,
20.340500532845102,
26.076772920536648,
9.634574414815917,
12.383524058135325,
19.52490293798709,
18.7052689091707,
11.174175978943147,
15.544285010137017,
16.586196879498914,
21.039134708027973,
0.7305023203691496,
10.21530980136746,
19.70192400574576,
4.052523098090926,
1.149887587953069,
21.19778468956815
]
},
"mode": "markers",
"type": "scatter",
"uid": "c9c7afc5-ad21-11e8-83e4-645aede86e5b",
"x": [
0.8719223372116345,
0.9025555914608151,
0.11356812277177875,
0.11130403512566589,
0.29989073562068136,
0.9147434907897669,
0.4744799031510898,
0.8483283268053516,
0.5181282112212632,
0.9905895846713948,
0.5713303391935799,
0.2877280915311108,
0.10367835901149913,
0.4168549460993164,
0.23133613245400841,
0.058658403430964845,
0.2642517441610307,
0.6488407132126095,
0.9785523435019607,
0.8717382336927328,
0.6285561804526444,
0.8399431821581193,
0.047878264975788176,
0.3534662140175273,
0.9235845003068142,
0.1445111432350592,
0.8166237013851174,
0.005081247877337103,
0.8879391341829255,
0.19619862872458982,
0.7434509471362691,
0.3316215610387655,
0.04393236525933686,
0.8947792245028668,
0.9825951432857912,
0.41413281848180306,
0.21626601394903044,
0.16245747064510196,
0.4105204737042506,
0.7236808472010895,
0.3489380579116269,
0.8908524856739101,
0.5122168888153052,
0.6589144372108674,
0.3635703386660024,
0.4217273968981342,
0.5608119481404433,
0.45741822209946714,
0.30486659448382813,
0.04818855961505841,
0.4954911844915122,
0.6994337301861913,
0.14084583618040514,
0.44453081841020037,
0.2903851102155799,
0.5956707884878416,
0.5380490494461626,
0.05619877307985499,
0.2223058348057647,
0.6886805689748245,
0.21131419294481868,
0.15114253777004605,
0.677146875407074,
0.0960466552353173,
0.6630687149915162,
0.7164680938231862,
0.19984614595180294,
0.8020111695555301,
0.039775539846378716,
0.6974634805337238,
0.4935459225052261,
0.9339378959826823,
0.33445498461945855,
0.1031174867315009,
0.7573183532531542,
0.3169803079020157,
0.4338220172147229,
0.6114353801636682,
0.0778656074266858,
0.2579270840116391,
0.803581461828242,
0.9756258356499767,
0.2051063742265431,
0.06426200099268975,
0.182366802096385,
0.9490570823810236,
0.47041717655883375,
0.9387087445053837,
0.989613958488937,
0.22770748495246085,
0.9750987747192132,
0.6916595030081959,
0.22820994140591588,
0.7894001916832935,
0.6287843868740289,
0.045351256724850075,
0.19184084778742483,
0.9570081928408264,
0.30872535893689257,
0.15401448072522206
],
"y": [
0.16590187396575606,
0.1938599382143723,
0.44238649804636976,
0.17189940490041222,
0.4588613569722405,
0.8290674965281956,
0.7293794989269148,
0.30901311682780586,
0.06285499753527068,
0.10284857072095532,
0.6439724947130874,
0.20751786571220276,
0.18485506212212977,
0.7771757244063144,
0.9390240943906215,
0.20085436592135808,
0.6635155977088434,
0.3511709138769571,
0.671021466220067,
0.7235739274895315,
0.6303729142991384,
0.6300566174327107,
0.9337058329435515,
0.975731814831301,
0.7283618479957994,
0.04310347286899441,
0.11259699025739833,
0.9262548669931727,
0.5455292500905919,
0.7389558177571717,
0.3471925100654538,
0.9026408623632496,
0.6507458484395608,
0.21029250854584325,
0.7225951267332132,
0.016971915942542992,
0.3681208579242653,
0.7493431122795632,
0.6500706167390807,
0.8255009810356668,
0.1957759436003682,
0.5723654377103435,
0.9084617313436522,
0.1782985143230652,
0.054144148201228814,
0.011727251704838682,
0.7412409876128055,
0.23116546547127115,
0.1629813685421776,
0.019487608784266808,
0.8695316094620937,
0.5429677692179246,
0.13554020991200144,
0.4166799077189297,
0.8809682195677552,
0.7841471666014945,
0.9869031079654652,
0.0657008132397695,
0.6196154151676412,
0.22165196328555092,
0.23689254409725946,
0.5038754939377746,
0.4302473815724661,
0.05383616659150103,
0.689027741379494,
0.5996066437361236,
0.16460672468666526,
0.2841158267476064,
0.4217833979421647,
0.9042167396040953,
0.021784928157279282,
0.9650150025937144,
0.09100153814894851,
0.4574295302246567,
0.28176404689774004,
0.6099369671926181,
0.03776651080230753,
0.7360844669232705,
0.7343279493578707,
0.5332878950971821,
0.555147039730562,
0.05330009918875822,
8.957498778805473e-05,
0.8250560601564566,
0.19515101277339342,
0.9523583536532184,
0.5396081072453808,
0.5451822570098825,
0.15522734037512442,
0.29102244423933954,
0.9493328733969231,
0.6821168704520659,
0.15035536935696237,
0.07777443301464804,
0.7107002807738756,
0.9704510749557056,
0.44211610288719905,
0.5002637333851094,
0.8437244688221681,
0.3392295077909119
]
}
],
"layout": {}
},
"text/html": [
"