{
"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",
"\n",
"plotly.__version__"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Static Image Export\n",
"New in version 3.2.0. It's now possible to programmatically export figures as high quality static images while fully offline.\n",
"\n",
"#### Install Dependencies\n",
"Static image generation requires the [orca](https://github.com/plotly/orca) commandline utility and the [psutil](https://github.com/giampaolo/psutil) Python library. There are 3 general approach to installing these dependencies.\n",
"\n",
"##### conda\n",
"Using the [conda](https://conda.io/docs/) package manager, you can install these dependencies in a single command:\n",
"```\n",
"$ conda install -c plotly plotly-orca psutil\n",
"```\n",
"\n",
"**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",
"\n",
"##### npm + pip\n",
"You can use the [npm](https://www.npmjs.com/get-npm) package manager to install `orca` (and its `electron` dependency), and then use pip to install `psutil`:\n",
"\n",
"```\n",
"$ npm install -g electron@1.8.4 orca\n",
"$ pip install psutil\n",
"```\n",
"\n",
"##### Standalone Binaries + pip\n",
"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 [README](https://github.com/plotly/orca) to install orca and add it to your system `PATH`. Then use pip to install `psutil`.\n",
"\n",
"```\n",
"$ pip install psutil\n",
"```"
]
},
{
"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": [
"from plotly.offline import iplot, init_notebook_mode\n",
"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.7032800642424858,
0.24757418670436437,
0.850231406302311,
0.7269997185006348,
0.7736910305966166,
0.21738892388348108,
0.13981304445625264,
0.1032348080562766,
0.02821220014870829,
0.5900937513611021,
0.5803059566567589,
0.5184066511045357,
0.300631608233064,
0.5787320544524599,
0.87064363697075,
0.09180262458187072,
0.3706085241439787,
0.35897442878784935,
0.697004103276674,
0.18434090330027764,
0.5025603829971418,
0.41649969553948973,
0.6032136946340806,
0.9104028874943139,
0.30300468301440786,
0.7074693952039917,
0.9754000472388398,
0.20904563285704514,
0.7526812527536917,
0.738853725143385,
0.5461736453769351,
0.9478735507480681,
0.4445077271641251,
0.42345646789758606,
0.3876206334471164,
0.39501551589058237,
0.9049295858434862,
0.654288398866838,
0.13651806352427798,
0.6905118700899766,
0.7142266546842715,
0.05721227732797396,
0.8433409998287461,
0.009429025064083163,
0.0024110573818197922,
0.19523978445644463,
0.3635866879259203,
0.24086664482408326,
0.5673361489713625,
0.582056312293562,
0.9281770230953478,
0.8307927661113439,
0.08619528583428082,
0.45149563185189967,
0.9392831378714728,
0.907508375416507,
0.9001241598087534,
0.30074361303052066,
0.276613486935112,
0.21828877536176639,
0.34664535281052544,
0.9398927103037503,
0.35635505376200294,
0.7702409649738096,
0.43376537086416966,
0.5396044084863187,
0.6275032828817475,
0.10883772095410404,
0.7057470901966637,
0.7796143474827822,
0.7903750317632836,
0.5504174944442001,
0.9451373752398228,
0.14355253494865694,
0.4217308509174288,
0.9266090985062901,
0.45909730916990477,
0.6825146592700362,
0.49612673723505596,
0.7331687802368156,
0.263287412636519,
0.9568011996411925,
0.954227457290215,
0.014052953874223784,
0.19412941167853814,
0.6392600764889104,
0.35334492784806726,
0.5468212571167532,
0.6577007735862824,
0.7844144561902585,
0.992992586296435,
0.3324536521452648,
0.9345896641403021,
0.2642867048036279,
0.26982116636684383,
0.8502660003280738,
0.09789746063560134,
0.1876815314289345,
0.011229196335044711,
0.04917299904496253
],
"colorscale": "Viridis",
"opacity": 0.6,
"size": [
7.021864413335317,
0.32756771065634904,
3.683898726846601,
0.8644338498299331,
14.2923601367526,
14.151913306097077,
9.305373166751707,
18.58610295065788,
5.209031818161685,
24.44842902186226,
14.998385629671832,
24.08280004441506,
26.49594553865206,
9.597657932556212,
7.136950475651398,
9.413263038510944,
23.360323584352418,
19.55021500763949,
11.490922178864341,
26.516252866825397,
16.30190945524968,
6.2224447621074574,
7.942139029482997,
23.49954430780135,
29.01857070741392,
14.473292207341581,
18.01548251401422,
5.193704922377737,
21.965278354327925,
7.815992227891488,
9.954065597087165,
21.879171409954633,
10.324421164440821,
25.174368851020375,
17.231210595201276,
20.21612095754354,
19.216503475095514,
16.584549287151184,
13.169239416831491,
19.31870727597413,
6.591425780953015,
19.654238266345462,
11.462541012638152,
21.17765069105972,
27.27740611791815,
13.443105571220395,
19.38006649171329,
15.066047595060958,
20.150964439405694,
5.521581771437773,
13.340226807799962,
28.22380335867491,
13.952785407127328,
28.050689555557152,
7.2721705701863835,
1.7459138913852423,
25.86900036369387,
27.129694888954912,
1.181659050453674,
5.776942971695988,
22.40303444589238,
8.58616105804205,
4.137854818632056,
10.568272428182931,
5.800697567319278,
18.75673634277205,
5.963749096571256,
3.4217040191037142,
1.382492138346133,
19.871013449753544,
20.498109272160107,
24.95587116258172,
11.881915003190656,
12.700801864251275,
19.281612977162403,
13.239777539405997,
7.506267143630439,
14.923101895655892,
1.6726559614850323,
28.279581148858362,
0.1254577261435874,
11.94954398987971,
22.742335439774568,
5.165075754182754,
16.279869655357714,
19.801427629960344,
1.066076371047715,
21.36766016809474,
25.620776717694195,
4.039042179459064,
2.4879705900385094,
11.88555228190331,
28.450880031870664,
13.882697749284072,
21.458783210242522,
6.5376814411067485,
0.8847736758071423,
7.866001929345163,
14.981842980574777,
27.771590762677487
]
},
"mode": "markers",
"type": "scatter",
"uid": "ae33b438-ad21-11e8-baa2-645aede86e5b",
"x": [
0.5314101574669423,
0.7665914603739712,
0.8722418789617734,
0.7805160441885617,
0.026389623430586262,
0.07268929388835799,
0.9392705963723869,
0.29482615184173,
0.6521084568370011,
0.9082244415961724,
0.5259623649680045,
0.019573378136458208,
0.5871082286306928,
0.9436067855960633,
0.5829071903718851,
0.95657069240182,
0.5425389953581613,
0.26552262011469785,
0.04872881388051331,
0.639332815248129,
0.8633102309924954,
0.05969362036123582,
0.3670212670898465,
0.14434884169331275,
0.6772088469783775,
0.9421372521691164,
0.7351093292157235,
0.19107790460987184,
0.9713264374971536,
0.8255571509321519,
0.21360139269265666,
0.8256267946499067,
0.19904740620887929,
0.5024679279093731,
0.7418041333428258,
0.3583045901668115,
0.47143586724168574,
0.12295078225598866,
0.29173059790641287,
0.2942163185462784,
0.9021491106101691,
0.7256365602021586,
0.3574115204750107,
0.1916027664799792,
0.38303508936326347,
0.10150780298368223,
0.6952456288140355,
0.6006999788499843,
0.7201807818075019,
0.889744793015561,
0.15032000807908508,
0.7152063995079676,
0.8261668899816271,
0.0707821938829386,
0.21064542443637235,
0.060667095874614274,
0.03426939715397359,
0.8349801285120416,
0.2656956026989866,
0.9260595152420458,
0.1458492793567039,
0.4215704550899043,
0.34567353393614675,
0.07474341144703234,
0.21980495541412237,
0.8595435608318246,
0.08406986164002672,
0.22753940503195746,
0.7631831050379071,
0.021737850229364142,
0.6240671207109296,
0.38365060446370214,
0.9672732626658542,
0.49311707320371057,
0.04751931045669555,
0.7028445159283238,
0.3962462552456415,
0.692876447011115,
0.6168830929517306,
0.9664540519011381,
0.28096601026094914,
0.4655646675176036,
0.20623763731552036,
0.10808471193653779,
0.9258615100053736,
0.3217279563224711,
0.7473767278330665,
0.847450705064022,
0.15880332756109228,
0.11531964398497985,
0.0644078623068538,
0.09208977366369964,
0.1829506615634937,
0.815843581085311,
0.14249065582189924,
0.8070932868942269,
0.28713044890543027,
0.8050422721639862,
0.8543392178914146,
0.044441922154205615
],
"y": [
0.38052055782882854,
0.4467664466999568,
0.8903969421421423,
0.7049474313199273,
0.7892409861392439,
0.25630187837196083,
0.8569742882802507,
0.6322463732435867,
0.4818733616507207,
0.38568107060660395,
0.8656423322914688,
0.9608671431549116,
0.9433418056882179,
0.5695428177662896,
0.9407425168764727,
0.19835556979192315,
0.14735235379678058,
0.6150390530128913,
0.6661226605477444,
0.5432561438024922,
0.13631739784415087,
0.6386889411222372,
0.5826108838137952,
0.19975415403264984,
0.9426771533818102,
0.37916104527618955,
0.42164834242594096,
0.3620008753943694,
0.6949055946726201,
0.6477334532394272,
0.7629215238759696,
0.2008668418955336,
0.6842603953100121,
0.5093580582955527,
0.8506571579045521,
0.28777915691107625,
0.710724371339061,
0.8845799560889204,
0.27986877682129807,
0.7375442775554232,
0.7111962870349411,
0.7694456470388144,
0.3985969798348341,
0.16920041892568083,
0.3735251151380903,
0.3371873475907522,
0.9077640171735539,
0.037973701038707564,
0.251132181067104,
0.9095477098863243,
0.6409087829171842,
0.5327030360832302,
0.5109578517658463,
0.8687436506177058,
0.9763894045198205,
0.6941478640238272,
0.25189353158539773,
0.06935236148369628,
0.37959017040216103,
0.08021041383429173,
0.7782635029956316,
0.7675503204649607,
0.6438301952427139,
0.3919938092800267,
0.23650359900175877,
0.5301645307735865,
0.5700571730740823,
0.6449254008734833,
0.7379262071900429,
0.6168982930854501,
0.5508745512640609,
0.8178032670987272,
0.634900517557973,
0.7447207119478318,
0.1802497751375164,
0.9413278350397853,
0.2899120851833338,
0.6850689344389296,
0.4706219895465521,
0.27625708093544776,
0.467256568673623,
0.5332179753620562,
0.2712811602694509,
0.3810951079445092,
0.10648293386056196,
0.8872018574181764,
0.6142782157201103,
0.9207972282589324,
0.8956557457296068,
0.6752611420429205,
0.5312958989730272,
0.0958642075746261,
0.507515896560122,
0.7461104326462709,
0.7599601169600706,
0.13543703188451195,
0.015406369878077308,
0.7784377316143277,
0.045904350018564966,
0.010103905041870975
]
}
],
"layout": {}
},
"text/html": [
"