How to plot multiple lines on the same y-axis using Plotly Express in Python

Short answer: fig = px.line(df, x=’Date’, y=df.columns[1:-6]) Where df.columns are the column names of the columns returned as a list, or a subset of the columns using, for example, df.columns[1:-6] The details Your code works fine But if you specifically do not want to apply the (somewhat laborious) add_trace() function to each line, you can … Read more

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

Use Pandas index in Plotly Express

Reference: https://plot.ly/python/px-arguments/#using-the-index-of-a-dataframe You can pass the index as reference explicitly. So in your case, this would be: import plotly.express as px iris = px.data.iris() fig = px.scatter(iris, x=iris.index, y=”sepal_length”) fig.show() — BONUS QUESTION: what if iris has a pd.MultiIndex? Use pd.MultiIndex.get_level_values. import plotly.express as px # dummy example for multiindex iris = px.data.iris().set_index([‘species’, ‘species_id’, iris.index]) … Read more

Same scale for x and y axis

Finally, this feature is implemented. layout = go.Layout(yaxis=dict(scaleanchor=”x”, scaleratio=1)) Update: in new versions of plotly, use the following: fig.update_yaxes( scaleanchor=”x”, scaleratio=1, ) See example here https://plot.ly/python/axes/#fixed-ratio-axes.

How to hide legend with Plotly Express and Plotly

After creating the figure in plotly, to disable the legend you can make use of this command: fig.update_layout(showlegend=False) For Advanced users: You can also enable/disable the legend for individual traces in a figure by setting the showlegend property of each trace. For instance: fig.add_trace(go.Scatter( x=[1, 2], y=[1, 2], showlegend=False)) You can view the examples here: … Read more

How to set the range of the y axis

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 change plotly figure size

Have you considered to use fig.update_layout( autosize=False, width=800, height=800,) and eventually reduce the size of your marker? UPDATE Full Code import plotly.graph_objs as go trace1 = go.Scatter( x=x1_tsne, # x-coordinates of trace y=y1_tsne, # y-coordinates of trace mode=”markers +text “, # scatter mode (more in UG section 1) text = label3, opacity = 1, textposition=’top … Read more

Plotly: How to set the range of the y axis?

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

Setting Background color to transparent in Plotly plots

For a fully transparent plot, make sure to specify both the paper bgcolor and the plot’s: import plotly.plotly as py from plotly.graph_objs import * py.sign_in(”, ”) data = Data([ Bar( x=[‘Sivaranjani S’, ‘Vijayalakshmi C’, ‘Rajeshwari S’, ‘Shanthi Priscilla’, ‘Pandiyaraj G’, ‘Kamatchi S’, ‘MohanaPriya’, ‘Madhumitha G’, ‘Franklin Alphones Raj J’, ‘Akfaris Almaas’, ‘Biswajit Champati’, ‘Priya R’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)