This is not a duplicate of this.
Adding the <extra></extra>
makes sure the trace#
is removed from the graph. But is there a way I could make that the default setting?
I am creating a custom plotly theme and would like it to be the default setting, but it is included in the trace
class and not the layout
one. Also, adding it to every trace call in plotly.go
call is repetitive.
To recreate the graph-
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
world_df = pd.DataFrame({'date': {494: '2021-05-09',
495: '2021-05-10',
496: '2021-05-11',
497: '2021-05-12',
498: '2021-05-13',
499: '2021-05-14',
500: '2021-05-15',
501: '2021-05-16',
502: '2021-05-17',
503: '2021-05-18'},
'total_deaths': {494: 3293029.0,
495: 3303796.0,
496: 3317412.0,
497: 3331346.0,
498: 3344481.0,
499: 3357610.0,
500: 3369259.0,
501: 3379349.0,
502: 3389992.0,
503: 3404338.0}})
#Comment out line below for exact copy as the question (though I don't think it's necessary)
#world_df = pd.read_csv('https://github.com/vyaduvanshi/helper-files/raw/master/world_so.csv')
fig = make_subplots(rows=1, cols=2, subplot_titles=['Normal Scale','Logarithmic Scale'])
fig.add_scatter(x=world_df.date, y=world_df.total_deaths, row=1, col=1,
hovertemplate='Removed manually:%{y}<extra></extra>',line=dict(color='#DB2B39'))
fig.add_scatter(x=world_df.date, y=world_df.total_deaths, row=1, col=2, line=dict(color='#DB2B39'))
fig.update_yaxes(type="log", row=1, col=2)
fig.update_layout(title_text='Total Deaths', showlegend=False)
The template is this (very close to plotly default), just in case you need it
pio.templates['my_theme'] = go.layout.Template({
'data': {'bar': [{'error_x': {'color': '#2a3f5f'},
'error_y': {'color': '#2a3f5f'},
'marker': {'line': {'color': '#E5ECF6', 'width': 0.5}},
'type': 'bar'}],
'barpolar': [{'marker': {'line': {'color': '#E5ECF6', 'width': 0.5}}, 'type': 'barpolar'}],
'carpet': [{'aaxis': {'endlinecolor': '#2a3f5f',
'gridcolor': 'white',
'linecolor': 'white',
'minorgridcolor': 'white',
'startlinecolor': '#2a3f5f'},
'baxis': {'endlinecolor': '#2a3f5f',
'gridcolor': 'white',
'linecolor': 'white',
'minorgridcolor': 'white',
'startlinecolor': '#2a3f5f'},
'type': 'carpet'}],
'choropleth': [{'colorbar': {'outlinewidth': 0, 'ticks': ''}, 'type': 'choropleth'}],
'contour': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
'colorscale': [[0.0, '#0d0887'], [0.1111111111111111,
'#46039f'], [0.2222222222222222,
'#7201a8'], [0.3333333333333333,
'#9c179e'], [0.4444444444444444,
'#bd3786'], [0.5555555555555556,
'#d8576b'], [0.6666666666666666,
'#ed7953'], [0.7777777777777778,
'#fb9f3a'], [0.8888888888888888,
'#fdca26'], [1.0, '#f0f921']],
'type': 'contour'}],
'contourcarpet': [{'colorbar': {'outlinewidth': 0, 'ticks': ''}, 'type': 'contourcarpet'}],
'heatmap': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
'colorscale': [[0.0, '#0d0887'], [0.1111111111111111,
'#46039f'], [0.2222222222222222,
'#7201a8'], [0.3333333333333333,
'#9c179e'], [0.4444444444444444,
'#bd3786'], [0.5555555555555556,
'#d8576b'], [0.6666666666666666,
'#ed7953'], [0.7777777777777778,
'#fb9f3a'], [0.8888888888888888,
'#fdca26'], [1.0, '#f0f921']],
'type': 'heatmap'}],
'heatmapgl': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
'colorscale': [[0.0, '#0d0887'], [0.1111111111111111,
'#46039f'], [0.2222222222222222,
'#7201a8'], [0.3333333333333333,
'#9c179e'], [0.4444444444444444,
'#bd3786'], [0.5555555555555556,
'#d8576b'], [0.6666666666666666,
'#ed7953'], [0.7777777777777778,
'#fb9f3a'], [0.8888888888888888,
'#fdca26'], [1.0, '#f0f921']],
'type': 'heatmapgl'}],
'histogram': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'histogram'}],
'histogram2d': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
'colorscale': [[0.0, '#0d0887'],
[0.1111111111111111, '#46039f'],
[0.2222222222222222, '#7201a8'],
[0.3333333333333333, '#9c179e'],
[0.4444444444444444, '#bd3786'],
[0.5555555555555556, '#d8576b'],
[0.6666666666666666, '#ed7953'],
[0.7777777777777778, '#fb9f3a'],
[0.8888888888888888, '#fdca26'], [1.0,
'#f0f921']],
'type': 'histogram2d'}],
'histogram2dcontour': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
'colorscale': [[0.0, '#0d0887'],
[0.1111111111111111,
'#46039f'],
[0.2222222222222222,
'#7201a8'],
[0.3333333333333333,
'#9c179e'],
[0.4444444444444444,
'#bd3786'],
[0.5555555555555556,
'#d8576b'],
[0.6666666666666666,
'#ed7953'],
[0.7777777777777778,
'#fb9f3a'],
[0.8888888888888888,
'#fdca26'], [1.0, '#f0f921']],
'type': 'histogram2dcontour'}],
'mesh3d': [{'colorbar': {'outlinewidth': 0, 'ticks': ''}, 'type': 'mesh3d'}],
'parcoords': [{'line': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'parcoords'}],
'pie': [{'automargin': True, 'type': 'pie'}],
'scatter': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scatter',
'line':{'width':2.5}}],
'scatter3d': [{'line': {'colorbar': {'outlinewidth': 0, 'ticks': ''}},
'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}},
'type': 'scatter3d'}],
'scattercarpet': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scattercarpet'}],
'scattergeo': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scattergeo'}],
'scattergl': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scattergl'}],
'scattermapbox': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scattermapbox'}],
'scatterpolar': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scatterpolar'}],
'scatterpolargl': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scatterpolargl'}],
'scatterternary': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scatterternary'}],
'surface': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
'colorscale': [[0.0, '#0d0887'], [0.1111111111111111,
'#46039f'], [0.2222222222222222,
'#7201a8'], [0.3333333333333333,
'#9c179e'], [0.4444444444444444,
'#bd3786'], [0.5555555555555556,
'#d8576b'], [0.6666666666666666,
'#ed7953'], [0.7777777777777778,
'#fb9f3a'], [0.8888888888888888,
'#fdca26'], [1.0, '#f0f921']],
'type': 'surface'}],
'table': [{'cells': {'fill': {'color': '#EBF0F8'}, 'line': {'color': 'white'}},
'header': {'fill': {'color': '#C8D4E3'}, 'line': {'color': 'white'}},
'type': 'table'}]},
'layout': {'annotationdefaults': {'arrowcolor': '#2a3f5f', 'arrowhead': 0, 'arrowwidth': 1},
'autotypenumbers': 'strict',
'coloraxis': {'colorbar': {'outlinewidth': 0, 'ticks': ''}},
'colorscale': {'diverging': [[0, '#8e0152'], [0.1, '#c51b7d'],
[0.2, '#de77ae'], [0.3, '#f1b6da'],
[0.4, '#fde0ef'], [0.5, '#f7f7f7'],
[0.6, '#e6f5d0'], [0.7, '#b8e186'],
[0.8, '#7fbc41'], [0.9, '#4d9221'], [1,
'#276419']],
'sequential': [[0.0, '#0d0887'],
[0.1111111111111111, '#46039f'],
[0.2222222222222222, '#7201a8'],
[0.3333333333333333, '#9c179e'],
[0.4444444444444444, '#bd3786'],
[0.5555555555555556, '#d8576b'],
[0.6666666666666666, '#ed7953'],
[0.7777777777777778, '#fb9f3a'],
[0.8888888888888888, '#fdca26'], [1.0,
'#f0f921']],
'sequentialminus': [[0.0, '#0d0887'],
[0.1111111111111111, '#46039f'],
[0.2222222222222222, '#7201a8'],
[0.3333333333333333, '#9c179e'],
[0.4444444444444444, '#bd3786'],
[0.5555555555555556, '#d8576b'],
[0.6666666666666666, '#ed7953'],
[0.7777777777777778, '#fb9f3a'],
[0.8888888888888888, '#fdca26'],
[1.0, '#f0f921']]},
'colorway': ["#db2b39","#faa613","#3d405b","#2fbf71","#00a6fb"],
'font': {'color': '#2a3f5f'},
'geo': {'bgcolor': 'white',
'lakecolor': 'white',
'landcolor': '#E5ECF6',
'showlakes': True,
'showland': True,
'subunitcolor': 'white'},
'hoverlabel': {'align': 'left'},
'hovermode': 'closest',
'mapbox': {'style': 'light'},
'paper_bgcolor': 'white',
'plot_bgcolor': 'white',
'polar': {'angularaxis': {'gridcolor': 'white', 'linecolor': 'white', 'ticks': ''},
'bgcolor': '#E5ECF6',
'radialaxis': {'gridcolor': 'white', 'linecolor': 'white', 'ticks': ''}},
'scene': {'xaxis': {'backgroundcolor': '#E5ECF6',
'gridcolor': 'white',
'gridwidth': 2,
'linecolor': 'white',
'showbackground': True,
'ticks': '',
'zerolinecolor': 'white'},
'yaxis': {'backgroundcolor': '#E5ECF6',
'gridcolor': 'white',
'gridwidth': 2,
'linecolor': 'white',
'showbackground': True,
'ticks': '',
'zerolinecolor': 'white'},
'zaxis': {'backgroundcolor': '#E5ECF6',
'gridcolor': 'white',
'gridwidth': 2,
'linecolor': 'white',
'showbackground': True,
'ticks': '',
'zerolinecolor': 'white'}},
'shapedefaults': {'line': {'color': '#2a3f5f'}},
'ternary': {'aaxis': {'gridcolor': 'white', 'linecolor': 'white', 'ticks': ''},
'baxis': {'gridcolor': 'white', 'linecolor': 'white', 'ticks': ''},
'bgcolor': '#E5ECF6',
'caxis': {'gridcolor': 'white', 'linecolor': 'white', 'ticks': ''}},
'title': {'x': 0.5,
'font_size':30},
'xaxis': {'automargin': True,
'gridcolor': '#eeeeee',
'linecolor': 'white',
'ticks': '',
'title': {'standoff': 15},
'zerolinecolor': 'white',
'zerolinewidth': 2},
'yaxis': {'automargin': True,
'gridcolor': '#eeeeee',
'linecolor': 'white',
'ticks': '',
'title': {'standoff': 15},
'zerolinecolor': 'white',
'zerolinewidth': 2}}
})
Interestingly enough, I found a solution that does the trick!
Passing hoverlabel = dict(namelength=0)
to the trace calls removes the trace#
. Same can be implemented by passing it in the template. Here's the complete code-
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
world_df = pd.DataFrame({'date': {494: '2021-05-09',
495: '2021-05-10',
496: '2021-05-11',
497: '2021-05-12',
498: '2021-05-13',
499: '2021-05-14',
500: '2021-05-15',
501: '2021-05-16',
502: '2021-05-17',
503: '2021-05-18'},
'total_deaths': {494: 3293029.0,
495: 3303796.0,
496: 3317412.0,
497: 3331346.0,
498: 3344481.0,
499: 3357610.0,
500: 3369259.0,
501: 3379349.0,
502: 3389992.0,
503: 3404338.0}})
#Comment out line below for exact copy as the question (though I don't think it's necessary)
#world_df = pd.read_csv('https://github.com/vyaduvanshi/helper-files/raw/master/world_so.csv')
fig = make_subplots(rows=1, cols=2, subplot_titles=['Normal Scale','Logarithmic Scale'])
fig.add_scatter(x=world_df.date, y=world_df.total_deaths, row=1, col=1,
hovertemplate='Removed manually:%{y}',line=dict(color='#DB2B39'),
hoverlabel=dict(namelength=0))
fig.add_scatter(x=world_df.date, y=world_df.total_deaths, row=1, col=2, line=dict(color='#DB2B39'),
hoverlabel=dict(namelength=0))
fig.update_yaxes(type="log", row=1, col=2)
fig.update_layout(title_text='Total Deaths', showlegend=False)
Here's the same thing done in a template-
pio.templates['my_theme'] = go.layout.Template({
'data': {'bar': [{'error_x': {'color': '#2a3f5f'},
'error_y': {'color': '#2a3f5f'},
'marker': {'line': {'color': '#E5ECF6', 'width': 0.5}},
'type': 'bar'}],
'barpolar': [{'marker': {'line': {'color': '#E5ECF6', 'width': 0.5}}, 'type': 'barpolar'}],
'carpet': [{'aaxis': {'endlinecolor': '#2a3f5f',
'gridcolor': 'white',
'linecolor': 'white',
'minorgridcolor': 'white',
'startlinecolor': '#2a3f5f'},
'baxis': {'endlinecolor': '#2a3f5f',
'gridcolor': 'white',
'linecolor': 'white',
'minorgridcolor': 'white',
'startlinecolor': '#2a3f5f'},
'type': 'carpet'}],
'choropleth': [{'colorbar': {'outlinewidth': 0, 'ticks': ''}, 'type': 'choropleth'}],
'contour': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
'colorscale': [[0.0, '#0d0887'], [0.1111111111111111,
'#46039f'], [0.2222222222222222,
'#7201a8'], [0.3333333333333333,
'#9c179e'], [0.4444444444444444,
'#bd3786'], [0.5555555555555556,
'#d8576b'], [0.6666666666666666,
'#ed7953'], [0.7777777777777778,
'#fb9f3a'], [0.8888888888888888,
'#fdca26'], [1.0, '#f0f921']],
'type': 'contour'}],
'contourcarpet': [{'colorbar': {'outlinewidth': 0, 'ticks': ''}, 'type': 'contourcarpet'}],
'heatmap': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
'colorscale': [[0.0, '#0d0887'], [0.1111111111111111,
'#46039f'], [0.2222222222222222,
'#7201a8'], [0.3333333333333333,
'#9c179e'], [0.4444444444444444,
'#bd3786'], [0.5555555555555556,
'#d8576b'], [0.6666666666666666,
'#ed7953'], [0.7777777777777778,
'#fb9f3a'], [0.8888888888888888,
'#fdca26'], [1.0, '#f0f921']],
'type': 'heatmap'}],
'heatmapgl': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
'colorscale': [[0.0, '#0d0887'], [0.1111111111111111,
'#46039f'], [0.2222222222222222,
'#7201a8'], [0.3333333333333333,
'#9c179e'], [0.4444444444444444,
'#bd3786'], [0.5555555555555556,
'#d8576b'], [0.6666666666666666,
'#ed7953'], [0.7777777777777778,
'#fb9f3a'], [0.8888888888888888,
'#fdca26'], [1.0, '#f0f921']],
'type': 'heatmapgl'}],
'histogram': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'histogram'}],
'histogram2d': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
'colorscale': [[0.0, '#0d0887'],
[0.1111111111111111, '#46039f'],
[0.2222222222222222, '#7201a8'],
[0.3333333333333333, '#9c179e'],
[0.4444444444444444, '#bd3786'],
[0.5555555555555556, '#d8576b'],
[0.6666666666666666, '#ed7953'],
[0.7777777777777778, '#fb9f3a'],
[0.8888888888888888, '#fdca26'], [1.0,
'#f0f921']],
'type': 'histogram2d'}],
'histogram2dcontour': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
'colorscale': [[0.0, '#0d0887'],
[0.1111111111111111,
'#46039f'],
[0.2222222222222222,
'#7201a8'],
[0.3333333333333333,
'#9c179e'],
[0.4444444444444444,
'#bd3786'],
[0.5555555555555556,
'#d8576b'],
[0.6666666666666666,
'#ed7953'],
[0.7777777777777778,
'#fb9f3a'],
[0.8888888888888888,
'#fdca26'], [1.0, '#f0f921']],
'type': 'histogram2dcontour'}],
'mesh3d': [{'colorbar': {'outlinewidth': 0, 'ticks': ''}, 'type': 'mesh3d'}],
'parcoords': [{'line': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'parcoords'}],
'pie': [{'automargin': True, 'type': 'pie'}],
'scatter': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scatter',
'line':{'width':2.5}}],
'scatter3d': [{'line': {'colorbar': {'outlinewidth': 0, 'ticks': ''}},
'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}},
'type': 'scatter3d'}],
'scattercarpet': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scattercarpet'}],
'scattergeo': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scattergeo'}],
'scattergl': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scattergl'}],
'scattermapbox': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scattermapbox'}],
'scatterpolar': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scatterpolar'}],
'scatterpolargl': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scatterpolargl'}],
'scatterternary': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scatterternary'}],
'surface': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
'colorscale': [[0.0, '#0d0887'], [0.1111111111111111,
'#46039f'], [0.2222222222222222,
'#7201a8'], [0.3333333333333333,
'#9c179e'], [0.4444444444444444,
'#bd3786'], [0.5555555555555556,
'#d8576b'], [0.6666666666666666,
'#ed7953'], [0.7777777777777778,
'#fb9f3a'], [0.8888888888888888,
'#fdca26'], [1.0, '#f0f921']],
'type': 'surface'}],
'table': [{'cells': {'fill': {'color': '#EBF0F8'}, 'line': {'color': 'white'}},
'header': {'fill': {'color': '#C8D4E3'}, 'line': {'color': 'white'}},
'type': 'table'}]},
'layout': {'annotationdefaults': {'arrowcolor': '#2a3f5f', 'arrowhead': 0, 'arrowwidth': 1},
'autotypenumbers': 'strict',
'coloraxis': {'colorbar': {'outlinewidth': 0, 'ticks': ''}},
'colorscale': {'diverging': [[0, '#8e0152'], [0.1, '#c51b7d'],
[0.2, '#de77ae'], [0.3, '#f1b6da'],
[0.4, '#fde0ef'], [0.5, '#f7f7f7'],
[0.6, '#e6f5d0'], [0.7, '#b8e186'],
[0.8, '#7fbc41'], [0.9, '#4d9221'], [1,
'#276419']],
'sequential': [[0.0, '#0d0887'],
[0.1111111111111111, '#46039f'],
[0.2222222222222222, '#7201a8'],
[0.3333333333333333, '#9c179e'],
[0.4444444444444444, '#bd3786'],
[0.5555555555555556, '#d8576b'],
[0.6666666666666666, '#ed7953'],
[0.7777777777777778, '#fb9f3a'],
[0.8888888888888888, '#fdca26'], [1.0,
'#f0f921']],
'sequentialminus': [[0.0, '#0d0887'],
[0.1111111111111111, '#46039f'],
[0.2222222222222222, '#7201a8'],
[0.3333333333333333, '#9c179e'],
[0.4444444444444444, '#bd3786'],
[0.5555555555555556, '#d8576b'],
[0.6666666666666666, '#ed7953'],
[0.7777777777777778, '#fb9f3a'],
[0.8888888888888888, '#fdca26'],
[1.0, '#f0f921']]},
'colorway': ["#db2b39","#faa613","#3d405b","#2fbf71","#00a6fb"],
'font': {'color': '#2a3f5f'},
'geo': {'bgcolor': 'white',
'lakecolor': 'white',
'landcolor': '#E5ECF6',
'showlakes': True,
'showland': True,
'subunitcolor': 'white'},
'hoverlabel': {'align': 'left',
'namelength': 0},
'hovermode': 'closest',
'mapbox': {'style': 'light'},
'paper_bgcolor': 'white',
'plot_bgcolor': 'white',
'polar': {'angularaxis': {'gridcolor': 'white', 'linecolor': 'white', 'ticks': ''},
'bgcolor': '#E5ECF6',
'radialaxis': {'gridcolor': 'white', 'linecolor': 'white', 'ticks': ''}},
'scene': {'xaxis': {'backgroundcolor': '#E5ECF6',
'gridcolor': 'white',
'gridwidth': 2,
'linecolor': 'white',
'showbackground': True,
'ticks': '',
'zerolinecolor': 'white'},
'yaxis': {'backgroundcolor': '#E5ECF6',
'gridcolor': 'white',
'gridwidth': 2,
'linecolor': 'white',
'showbackground': True,
'ticks': '',
'zerolinecolor': 'white'},
'zaxis': {'backgroundcolor': '#E5ECF6',
'gridcolor': 'white',
'gridwidth': 2,
'linecolor': 'white',
'showbackground': True,
'ticks': '',
'zerolinecolor': 'white'}},
'shapedefaults': {'line': {'color': '#2a3f5f'}},
'ternary': {'aaxis': {'gridcolor': 'white', 'linecolor': 'white', 'ticks': ''},
'baxis': {'gridcolor': 'white', 'linecolor': 'white', 'ticks': ''},
'bgcolor': '#E5ECF6',
'caxis': {'gridcolor': 'white', 'linecolor': 'white', 'ticks': ''}},
'title': {'x': 0.5,
'font_size':30},
'xaxis': {'automargin': True,
'gridcolor': '#eeeeee',
'linecolor': 'white',
'ticks': '',
'title': {'standoff': 15},
'zerolinecolor': 'white',
'zerolinewidth': 2},
'yaxis': {'automargin': True,
'gridcolor': '#eeeeee',
'linecolor': 'white',
'ticks': '',
'title': {'standoff': 15},
'zerolinecolor': 'white',
'zerolinewidth': 2}}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With