Skip to content

Instantly share code, notes, and snippets.

@smcveigh-phunware
Created June 28, 2018 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smcveigh-phunware/8c834ca9481cf3e85e8ba3f78b277e33 to your computer and use it in GitHub Desktop.
Save smcveigh-phunware/8c834ca9481cf3e85e8ba3f78b277e33 to your computer and use it in GitHub Desktop.
Background image in each subplot?
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window.Plotly) {{require(['plotly'],function(plotly) {window.Plotly=plotly;});}}</script>"
],
"text/vnd.plotly.v1+html": [
"<script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window.Plotly) {{require(['plotly'],function(plotly) {window.Plotly=plotly;});}}</script>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"This is the format of your plot grid:\n",
"[ (1,1) x1,y1 ] [ (1,2) x2,y2 ]\n",
"\n"
]
},
{
"data": {
"application/vnd.plotly.v1+json": {
"data": [
{
"name": "sin(x)",
"type": "scatter",
"x": [
-1.5707963267948966,
-1.5066821910073498,
-1.442568055219803,
-1.3784539194322563,
-1.3143397836447095,
-1.2502256478571625,
-1.1861115120696157,
-1.121997376282069,
-1.0578832404945222,
-0.9937691047069754,
-0.9296549689194287,
-0.8655408331318818,
-0.801426697344335,
-0.7373125615567883,
-0.6731984257692414,
-0.6090842899816946,
-0.5449701541941478,
-0.4808560184066011,
-0.4167418826190543,
-0.35262774683150755,
-0.2885136110439608,
-0.2243994752564138,
-0.16028533946886703,
-0.09617120368132026,
-0.032057067893773494,
0.03205706789377327,
0.09617120368132004,
0.1602853394688668,
0.2243994752564138,
0.28851361104396056,
0.3526277468315073,
0.4167418826190541,
0.48085601840660086,
0.5449701541941478,
0.6090842899816944,
0.6731984257692414,
0.7373125615567879,
0.8014266973443349,
0.8655408331318815,
0.9296549689194284,
0.993769104706975,
1.057883240494522,
1.121997376282069,
1.1861115120696155,
1.2502256478571625,
1.314339783644709,
1.378453919432256,
1.4425680552198026,
1.5066821910073496,
1.5707963267948966
],
"xaxis": "x1",
"y": [
-1,
-0.9979453927503363,
-0.9917900138232462,
-0.9815591569910653,
-0.9672948630390295,
-0.9490557470106686,
-0.9269167573460217,
-0.9009688679024191,
-0.8713187041233893,
-0.8380881048918406,
-0.8014136218679566,
-0.7614459583691344,
-0.7183493500977276,
-0.6723008902613168,
-0.6234898018587335,
-0.5721166601221697,
-0.518392568310525,
-0.46253829024083537,
-0.40478334312239395,
-0.34536505442130777,
-0.2845275866310326,
-0.2225209339563144,
-0.15959989503337924,
-0.09602302590768182,
-0.03205157757165527,
0.03205157757165505,
0.09602302590768161,
0.15959989503337904,
0.2225209339563144,
0.2845275866310324,
0.34536505442130755,
0.4047833431223937,
0.46253829024083515,
0.518392568310525,
0.5721166601221694,
0.6234898018587335,
0.6723008902613166,
0.7183493500977275,
0.7614459583691342,
0.8014136218679565,
0.8380881048918404,
0.8713187041233892,
0.9009688679024191,
0.9269167573460216,
0.9490557470106686,
0.9672948630390293,
0.9815591569910653,
0.991790013823246,
0.9979453927503363,
1
],
"yaxis": "y1"
},
{
"name": "cos(x)",
"type": "scatter",
"x": [
-1.5707963267948966,
-1.5066821910073498,
-1.442568055219803,
-1.3784539194322563,
-1.3143397836447095,
-1.2502256478571625,
-1.1861115120696157,
-1.121997376282069,
-1.0578832404945222,
-0.9937691047069754,
-0.9296549689194287,
-0.8655408331318818,
-0.801426697344335,
-0.7373125615567883,
-0.6731984257692414,
-0.6090842899816946,
-0.5449701541941478,
-0.4808560184066011,
-0.4167418826190543,
-0.35262774683150755,
-0.2885136110439608,
-0.2243994752564138,
-0.16028533946886703,
-0.09617120368132026,
-0.032057067893773494,
0.03205706789377327,
0.09617120368132004,
0.1602853394688668,
0.2243994752564138,
0.28851361104396056,
0.3526277468315073,
0.4167418826190541,
0.48085601840660086,
0.5449701541941478,
0.6090842899816944,
0.6731984257692414,
0.7373125615567879,
0.8014266973443349,
0.8655408331318815,
0.9296549689194284,
0.993769104706975,
1.057883240494522,
1.121997376282069,
1.1861115120696155,
1.2502256478571625,
1.314339783644709,
1.378453919432256,
1.4425680552198026,
1.5066821910073496,
1.5707963267948966
],
"xaxis": "x2",
"y": [
6.123233995736766e-17,
0.06407021998071294,
0.127877161684506,
0.19115862870137226,
0.2536545839095073,
0.31510821802362077,
0.3752670048793742,
0.4338837391175582,
0.49071755200393796,
0.5455349012105487,
0.598110530491216,
0.6482283953077884,
0.6956825506034864,
0.7402779970753155,
0.7818314824680298,
0.8201722545969559,
0.8551427630053461,
0.886599306373,
0.9144126230158125,
0.9384684220497603,
0.9586678530366606,
0.9749279121818236,
0.9871817834144502,
0.9953791129491982,
0.9994862162006879,
0.9994862162006879,
0.9953791129491982,
0.9871817834144502,
0.9749279121818236,
0.9586678530366606,
0.9384684220497604,
0.9144126230158125,
0.8865993063730001,
0.8551427630053461,
0.820172254596956,
0.7818314824680298,
0.7402779970753157,
0.6956825506034865,
0.6482283953077888,
0.5981105304912161,
0.545534901210549,
0.49071755200393813,
0.4338837391175582,
0.3752670048793744,
0.31510821802362077,
0.25365458390950774,
0.19115862870137248,
0.12787716168450644,
0.06407021998071316,
6.123233995736766e-17
],
"yaxis": "y2"
}
],
"layout": {
"images": [
{
"layer": "below",
"opacity": 0.5,
"sizex": 2,
"sizey": 1.5,
"sizing": "stretch",
"source": "https://images.plot.ly/language-icons/api-home/python-logo.png",
"x": -1,
"xanchor": "top",
"xref": "x",
"y": 0.75,
"yanchor": "left",
"yref": "y"
}
],
"xaxis1": {
"anchor": "y1",
"domain": [
0,
0.45
]
},
"xaxis2": {
"anchor": "y2",
"domain": [
0.55,
1
]
},
"yaxis1": {
"anchor": "x1",
"domain": [
0,
1
]
},
"yaxis2": {
"anchor": "x2",
"domain": [
0,
1
]
}
}
},
"text/html": [
"<div id=\"792af4bf-35ec-4c9c-86b6-5869f62d7161\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"792af4bf-35ec-4c9c-86b6-5869f62d7161\", [{\"type\": \"scatter\", \"name\": \"sin(x)\", \"x\": [-1.5707963267948966, -1.5066821910073498, -1.442568055219803, -1.3784539194322563, -1.3143397836447095, -1.2502256478571625, -1.1861115120696157, -1.121997376282069, -1.0578832404945222, -0.9937691047069754, -0.9296549689194287, -0.8655408331318818, -0.801426697344335, -0.7373125615567883, -0.6731984257692414, -0.6090842899816946, -0.5449701541941478, -0.4808560184066011, -0.4167418826190543, -0.35262774683150755, -0.2885136110439608, -0.2243994752564138, -0.16028533946886703, -0.09617120368132026, -0.032057067893773494, 0.03205706789377327, 0.09617120368132004, 0.1602853394688668, 0.2243994752564138, 0.28851361104396056, 0.3526277468315073, 0.4167418826190541, 0.48085601840660086, 0.5449701541941478, 0.6090842899816944, 0.6731984257692414, 0.7373125615567879, 0.8014266973443349, 0.8655408331318815, 0.9296549689194284, 0.993769104706975, 1.057883240494522, 1.121997376282069, 1.1861115120696155, 1.2502256478571625, 1.314339783644709, 1.378453919432256, 1.4425680552198026, 1.5066821910073496, 1.5707963267948966], \"y\": [-1.0, -0.9979453927503363, -0.9917900138232462, -0.9815591569910653, -0.9672948630390295, -0.9490557470106686, -0.9269167573460217, -0.9009688679024191, -0.8713187041233893, -0.8380881048918406, -0.8014136218679566, -0.7614459583691344, -0.7183493500977276, -0.6723008902613168, -0.6234898018587335, -0.5721166601221697, -0.518392568310525, -0.46253829024083537, -0.40478334312239395, -0.34536505442130777, -0.2845275866310326, -0.2225209339563144, -0.15959989503337924, -0.09602302590768182, -0.03205157757165527, 0.03205157757165505, 0.09602302590768161, 0.15959989503337904, 0.2225209339563144, 0.2845275866310324, 0.34536505442130755, 0.4047833431223937, 0.46253829024083515, 0.518392568310525, 0.5721166601221694, 0.6234898018587335, 0.6723008902613166, 0.7183493500977275, 0.7614459583691342, 0.8014136218679565, 0.8380881048918404, 0.8713187041233892, 0.9009688679024191, 0.9269167573460216, 0.9490557470106686, 0.9672948630390293, 0.9815591569910653, 0.991790013823246, 0.9979453927503363, 1.0], \"xaxis\": \"x1\", \"yaxis\": \"y1\"}, {\"type\": \"scatter\", \"name\": \"cos(x)\", \"x\": [-1.5707963267948966, -1.5066821910073498, -1.442568055219803, -1.3784539194322563, -1.3143397836447095, -1.2502256478571625, -1.1861115120696157, -1.121997376282069, -1.0578832404945222, -0.9937691047069754, -0.9296549689194287, -0.8655408331318818, -0.801426697344335, -0.7373125615567883, -0.6731984257692414, -0.6090842899816946, -0.5449701541941478, -0.4808560184066011, -0.4167418826190543, -0.35262774683150755, -0.2885136110439608, -0.2243994752564138, -0.16028533946886703, -0.09617120368132026, -0.032057067893773494, 0.03205706789377327, 0.09617120368132004, 0.1602853394688668, 0.2243994752564138, 0.28851361104396056, 0.3526277468315073, 0.4167418826190541, 0.48085601840660086, 0.5449701541941478, 0.6090842899816944, 0.6731984257692414, 0.7373125615567879, 0.8014266973443349, 0.8655408331318815, 0.9296549689194284, 0.993769104706975, 1.057883240494522, 1.121997376282069, 1.1861115120696155, 1.2502256478571625, 1.314339783644709, 1.378453919432256, 1.4425680552198026, 1.5066821910073496, 1.5707963267948966], \"y\": [6.123233995736766e-17, 0.06407021998071294, 0.127877161684506, 0.19115862870137226, 0.2536545839095073, 0.31510821802362077, 0.3752670048793742, 0.4338837391175582, 0.49071755200393796, 0.5455349012105487, 0.598110530491216, 0.6482283953077884, 0.6956825506034864, 0.7402779970753155, 0.7818314824680298, 0.8201722545969559, 0.8551427630053461, 0.886599306373, 0.9144126230158125, 0.9384684220497603, 0.9586678530366606, 0.9749279121818236, 0.9871817834144502, 0.9953791129491982, 0.9994862162006879, 0.9994862162006879, 0.9953791129491982, 0.9871817834144502, 0.9749279121818236, 0.9586678530366606, 0.9384684220497604, 0.9144126230158125, 0.8865993063730001, 0.8551427630053461, 0.820172254596956, 0.7818314824680298, 0.7402779970753157, 0.6956825506034865, 0.6482283953077888, 0.5981105304912161, 0.545534901210549, 0.49071755200393813, 0.4338837391175582, 0.3752670048793744, 0.31510821802362077, 0.25365458390950774, 0.19115862870137248, 0.12787716168450644, 0.06407021998071316, 6.123233995736766e-17], \"xaxis\": \"x2\", \"yaxis\": \"y2\"}], {\"xaxis1\": {\"domain\": [0.0, 0.45], \"anchor\": \"y1\"}, \"yaxis1\": {\"domain\": [0.0, 1.0], \"anchor\": \"x1\"}, \"xaxis2\": {\"domain\": [0.55, 1.0], \"anchor\": \"y2\"}, \"yaxis2\": {\"domain\": [0.0, 1.0], \"anchor\": \"x2\"}, \"images\": [{\"source\": \"https://images.plot.ly/language-icons/api-home/python-logo.png\", \"xref\": \"x\", \"yref\": \"y\", \"x\": -1, \"y\": 0.75, \"sizex\": 2, \"sizey\": 1.5, \"sizing\": \"stretch\", \"opacity\": 0.5, \"layer\": \"below\", \"xanchor\": \"top\", \"yanchor\": \"left\"}]}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\"})});</script>"
],
"text/vnd.plotly.v1+html": [
"<div id=\"792af4bf-35ec-4c9c-86b6-5869f62d7161\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"792af4bf-35ec-4c9c-86b6-5869f62d7161\", [{\"type\": \"scatter\", \"name\": \"sin(x)\", \"x\": [-1.5707963267948966, -1.5066821910073498, -1.442568055219803, -1.3784539194322563, -1.3143397836447095, -1.2502256478571625, -1.1861115120696157, -1.121997376282069, -1.0578832404945222, -0.9937691047069754, -0.9296549689194287, -0.8655408331318818, -0.801426697344335, -0.7373125615567883, -0.6731984257692414, -0.6090842899816946, -0.5449701541941478, -0.4808560184066011, -0.4167418826190543, -0.35262774683150755, -0.2885136110439608, -0.2243994752564138, -0.16028533946886703, -0.09617120368132026, -0.032057067893773494, 0.03205706789377327, 0.09617120368132004, 0.1602853394688668, 0.2243994752564138, 0.28851361104396056, 0.3526277468315073, 0.4167418826190541, 0.48085601840660086, 0.5449701541941478, 0.6090842899816944, 0.6731984257692414, 0.7373125615567879, 0.8014266973443349, 0.8655408331318815, 0.9296549689194284, 0.993769104706975, 1.057883240494522, 1.121997376282069, 1.1861115120696155, 1.2502256478571625, 1.314339783644709, 1.378453919432256, 1.4425680552198026, 1.5066821910073496, 1.5707963267948966], \"y\": [-1.0, -0.9979453927503363, -0.9917900138232462, -0.9815591569910653, -0.9672948630390295, -0.9490557470106686, -0.9269167573460217, -0.9009688679024191, -0.8713187041233893, -0.8380881048918406, -0.8014136218679566, -0.7614459583691344, -0.7183493500977276, -0.6723008902613168, -0.6234898018587335, -0.5721166601221697, -0.518392568310525, -0.46253829024083537, -0.40478334312239395, -0.34536505442130777, -0.2845275866310326, -0.2225209339563144, -0.15959989503337924, -0.09602302590768182, -0.03205157757165527, 0.03205157757165505, 0.09602302590768161, 0.15959989503337904, 0.2225209339563144, 0.2845275866310324, 0.34536505442130755, 0.4047833431223937, 0.46253829024083515, 0.518392568310525, 0.5721166601221694, 0.6234898018587335, 0.6723008902613166, 0.7183493500977275, 0.7614459583691342, 0.8014136218679565, 0.8380881048918404, 0.8713187041233892, 0.9009688679024191, 0.9269167573460216, 0.9490557470106686, 0.9672948630390293, 0.9815591569910653, 0.991790013823246, 0.9979453927503363, 1.0], \"xaxis\": \"x1\", \"yaxis\": \"y1\"}, {\"type\": \"scatter\", \"name\": \"cos(x)\", \"x\": [-1.5707963267948966, -1.5066821910073498, -1.442568055219803, -1.3784539194322563, -1.3143397836447095, -1.2502256478571625, -1.1861115120696157, -1.121997376282069, -1.0578832404945222, -0.9937691047069754, -0.9296549689194287, -0.8655408331318818, -0.801426697344335, -0.7373125615567883, -0.6731984257692414, -0.6090842899816946, -0.5449701541941478, -0.4808560184066011, -0.4167418826190543, -0.35262774683150755, -0.2885136110439608, -0.2243994752564138, -0.16028533946886703, -0.09617120368132026, -0.032057067893773494, 0.03205706789377327, 0.09617120368132004, 0.1602853394688668, 0.2243994752564138, 0.28851361104396056, 0.3526277468315073, 0.4167418826190541, 0.48085601840660086, 0.5449701541941478, 0.6090842899816944, 0.6731984257692414, 0.7373125615567879, 0.8014266973443349, 0.8655408331318815, 0.9296549689194284, 0.993769104706975, 1.057883240494522, 1.121997376282069, 1.1861115120696155, 1.2502256478571625, 1.314339783644709, 1.378453919432256, 1.4425680552198026, 1.5066821910073496, 1.5707963267948966], \"y\": [6.123233995736766e-17, 0.06407021998071294, 0.127877161684506, 0.19115862870137226, 0.2536545839095073, 0.31510821802362077, 0.3752670048793742, 0.4338837391175582, 0.49071755200393796, 0.5455349012105487, 0.598110530491216, 0.6482283953077884, 0.6956825506034864, 0.7402779970753155, 0.7818314824680298, 0.8201722545969559, 0.8551427630053461, 0.886599306373, 0.9144126230158125, 0.9384684220497603, 0.9586678530366606, 0.9749279121818236, 0.9871817834144502, 0.9953791129491982, 0.9994862162006879, 0.9994862162006879, 0.9953791129491982, 0.9871817834144502, 0.9749279121818236, 0.9586678530366606, 0.9384684220497604, 0.9144126230158125, 0.8865993063730001, 0.8551427630053461, 0.820172254596956, 0.7818314824680298, 0.7402779970753157, 0.6956825506034865, 0.6482283953077888, 0.5981105304912161, 0.545534901210549, 0.49071755200393813, 0.4338837391175582, 0.3752670048793744, 0.31510821802362077, 0.25365458390950774, 0.19115862870137248, 0.12787716168450644, 0.06407021998071316, 6.123233995736766e-17], \"xaxis\": \"x2\", \"yaxis\": \"y2\"}], {\"xaxis1\": {\"domain\": [0.0, 0.45], \"anchor\": \"y1\"}, \"yaxis1\": {\"domain\": [0.0, 1.0], \"anchor\": \"x1\"}, \"xaxis2\": {\"domain\": [0.55, 1.0], \"anchor\": \"y2\"}, \"yaxis2\": {\"domain\": [0.0, 1.0], \"anchor\": \"x2\"}, \"images\": [{\"source\": \"https://images.plot.ly/language-icons/api-home/python-logo.png\", \"xref\": \"x\", \"yref\": \"y\", \"x\": -1, \"y\": 0.75, \"sizex\": 2, \"sizey\": 1.5, \"sizing\": \"stretch\", \"opacity\": 0.5, \"layer\": \"below\", \"xanchor\": \"top\", \"yanchor\": \"left\"}]}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\"})});</script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import plotly.offline as py\n",
"import plotly.graph_objs as go\n",
"from plotly import tools\n",
"import numpy as np\n",
"\n",
"\n",
"py.init_notebook_mode(connected=True)\n",
"\n",
"fig = tools.make_subplots(rows=1, cols=2)\n",
"\n",
"xi = np.linspace(-np.pi/2, np.pi/2)\n",
"\n",
"sin = go.Scatter(\n",
" name='sin(x)',\n",
" x=xi,\n",
" y=np.sin(xi)\n",
")\n",
"\n",
"cos = go.Scatter(\n",
" name='cos(x)',\n",
" x=xi,\n",
" y=np.cos(xi)\n",
")\n",
"\n",
"fig.append_trace(sin, 1, 1)\n",
"fig.append_trace(cos, 1, 2)\n",
"\n",
"url = \"https://images.plot.ly/language-icons/api-home/python-logo.png\"\n",
"\n",
"fig['layout'].update(\n",
" images=[\n",
" dict(\n",
" source=url,\n",
" xref=\"x\",\n",
" yref=\"y\",\n",
" x=-1,\n",
" y=0.75,\n",
" sizex=2,\n",
" sizey=1.5,\n",
" sizing=\"stretch\",\n",
" opacity=0.5,\n",
" layer=\"below\",\n",
" xanchor=\"top\",\n",
" yanchor=\"left\"\n",
" )\n",
" ]\n",
")\n",
"\n",
"py.iplot(fig)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment