How to customize hover-template on with what information to show

For Plotly Express, you need to use the custom_data argument when you create the figure. For example: fig = px.scatter( data_frame=df, x=’ColX’, y=’ColY’, custom_data=[‘Col1’, ‘Col2’, ‘Col3’] ) and then modify it using update_traces and hovertemplate, referencing it as customdata. For example: fig.update_traces( hovertemplate=”<br>”.join([ “ColX: %{x}”, “ColY: %{y}”, “Col1: %{customdata[0]}”, “Col2: %{customdata[1]}”, “Col3: %{customdata[2]}”, ]) ) …

Read more

how to hide plotly yaxis title (in python)?

Solution You need to use visible=False inside fig.update_yaxes() or fig.update_layout() as follows. For more details see the documentation for plotly.graph_objects.Figure. # Option-1: using fig.update_yaxes() fig.update_yaxes(visible=False, showticklabels=False) # Option-2: using fig.update_layout() fig.update_layout(yaxis={‘visible’: False, ‘showticklabels’: False}) # Option-3: using fig.update_layout() + dict-flattening shorthand fig.update_layout(yaxis_visible=False, yaxis_showticklabels=False) Try doing the following to test this: # Set the visibility ON …

Read more

Plotly.js default colors list

For Plotly.js, the default color list is given in the source code: ‘#1f77b4’, // muted blue ‘#ff7f0e’, // safety orange ‘#2ca02c’, // cooked asparagus green ‘#d62728’, // brick red ‘#9467bd’, // muted purple ‘#8c564b’, // chestnut brown ‘#e377c2’, // raspberry yogurt pink ‘#7f7f7f’, // middle gray ‘#bcbd22’, // curry yellow-green ‘#17becf’ // blue-teal For Plotly …

Read more

Set the range of the y axis in Plotly

Update for newer versions When setting up a figure you can use plotly’s magic underscore notation and specify layout_yaxis_range=[<from_value>, <to_value>] like this: fig = go.Figure(data=go.Scatter(x=x, y=y, mode=”lines”), layout_yaxis_range=[-4,4]) Or if you’ve already got a figure named fig, you can use: fig.update_layout(yaxis_range=[-4,4]) And: fig.update(layout_yaxis_range = [-4,4]) Or: fig.update_yaxes(range = [-4,4]) Figure: Complete code: # imports import …

Read more

How to get Plotly.js default colors list?

According to the source code, the default color list is: ‘#1f77b4’, // muted blue ‘#ff7f0e’, // safety orange ‘#2ca02c’, // cooked asparagus green ‘#d62728’, // brick red ‘#9467bd’, // muted purple ‘#8c564b’, // chestnut brown ‘#e377c2’, // raspberry yogurt pink ‘#7f7f7f’, // middle gray ‘#bcbd22’, // curry yellow-green ‘#17becf’ // blue-teal If you have more …

Read more

How to save plotly express plot into a html or static image file?

Updated answer: With newer versions of plotly, static Image export in Python is a breeze. Just make sure to install kaleido using: pip install -U kaleido or, for Anaconda: conda install -c conda-forge python-kaleido And then run fig.write_image(“yourfile.png”) Filetypes such as .jpeg and .pdf are also available options. Producing an individual html file is still …

Read more

How to change variable/label names for the legend in a plotly express line chart

The answer: Without changing the data source, a complete replacement of names both in the legend, legendgroup and hovertemplate will require: newnames = {‘col1′:’hello’, ‘col2’: ‘hi’} fig.for_each_trace(lambda t: t.update(name = newnames[t.name], legendgroup = newnames[t.name], hovertemplate = t.hovertemplate.replace(t.name, newnames[t.name]) ) ) Plot: The details: Using fig.for_each_trace(lambda t: t.update(name = newnames[t.name])) …you can change the names in …

Read more