Skip to content

Instantly share code, notes, and snippets.

@Paul-Aime
Last active December 22, 2020 10:58
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 Paul-Aime/52ef7ce08cb98ec523b9d36f7f2bb6ad to your computer and use it in GitHub Desktop.
Save Paul-Aime/52ef7ce08cb98ec523b9d36f7f2bb6ad to your computer and use it in GitHub Desktop.
Example for the bug described in the Plotly Community Forum [link](https://community.plotly.com/t/go-figurewidget-layout-updating-itself-when-re-running-cell/48409)
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import plotly.graph_objects as go"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Create a colorbar with go.Bar\n",
"\n",
"cname = \"fall\"\n",
"num_points = 200\n",
"width = 500\n",
"height = 50\n",
"\n",
"cmin, cmax = 0, 1\n",
"step = (cmax - cmin) / (num_points - 1)\n",
"linspace = [cmin + (x * step) for x in range(num_points)]\n",
"\n",
"data = [\n",
" go.Bar(\n",
" orientation=\"h\",\n",
" x=[step] * num_points, # width\n",
" y=[cname] * num_points, # group\n",
" hoverinfo=\"skip\",\n",
" marker=dict(\n",
" colorscale=cname,\n",
" color=linspace,\n",
" line_width=0,\n",
" cmin=cmin,\n",
" cmax=cmax,\n",
" ),\n",
" ),\n",
"]\n",
"\n",
"layout = dict(\n",
" barmode=\"stack\",\n",
" barnorm=\"\",\n",
" bargap=0,\n",
" height=height,\n",
" width=width,\n",
" margin=dict(b=0, t=0, l=0, r=0),\n",
" paper_bgcolor=\"rgba(0,0,0,0)\",\n",
" plot_bgcolor=\"rgba(0,0,0,0)\",\n",
" modebar_bgcolor=\"rgba(0,0,0,0)\",\n",
" showlegend=False,\n",
" yaxis=dict(showgrid=False, showticklabels=False),\n",
" xaxis=dict(\n",
" showgrid=False,\n",
" showticklabels=False,\n",
" ticks=\"\",\n",
" ),\n",
")\n",
"\n",
"fig = go.FigureWidget(data=data, layout=layout)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8f51dfd75928451b896051c8ca0495be",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"FigureWidget({\n",
" 'data': [{'hoverinfo': 'skip',\n",
" 'marker': {'cmax': 1,\n",
" …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'rgba(0,0,0,0)'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fig.layout.paper_bgcolor"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8f51dfd75928451b896051c8ca0495be",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"FigureWidget({\n",
" 'data': [{'hoverinfo': 'skip',\n",
" 'marker': {'cmax': 1,\n",
" …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'rgba(0,0,0,0)'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fig.layout.paper_bgcolor"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"=== Executing: ===\n",
"fig\n",
"=== Output: ===\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8f51dfd75928451b896051c8ca0495be",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"FigureWidget({\n",
" 'data': [{'hoverinfo': 'skip',\n",
" 'marker': {'cmax': 1,\n",
" …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%rerun 3 # Need to re-run manually for the bug to appears"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"=== Executing: ===\n",
"fig.layout.paper_bgcolor\n",
"=== Output: ===\n"
]
},
{
"data": {
"text/plain": [
"'rgba(0,0,0,0)'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%rerun 4 # Need to re-run manually for the bug to appears"
]
}
],
"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.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment