Skip to content

Instantly share code, notes, and snippets.

@jangedoo
Last active March 27, 2023 15: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 jangedoo/50230b95d706a9f075c5e26bbe0811d5 to your computer and use it in GitHub Desktop.
Save jangedoo/50230b95d706a9f075c5e26bbe0811d5 to your computer and use it in GitHub Desktop.
Plotly Cheatsheet

Change template

px.bar(..., template="simple_white")

Change axis legend labels

px.bar(..., labels={"gndr": "Gender", "cnt": "Total Participants"})

Show axis ticks for feach facet

fig.for_each_xaxis(lambda xaxis: xaxis.update(showticklabels=True))

fig.for_each_yaxis(lambda yaxis: yaxis.update(showticklabels=True))

Hide legend

fig.update_layout(showlegend=False)

Position legend differently

fig.update_layout(showlegend=True, legend=dict(yanchor="bottom", xanchor="right", y=0.3))

Rename legend names

fig.update_traces(selector={"name": "unique_skus"}, name="SKU")

fig.update_traces(selector=1, name="Product ID")

Add annotation

fig.add_annotation(text="<b>Bold</b> text <br> with break", xref="x domain", yref="y domain", x=0.6, y=0.8, showarrow=False)

Change text template

fig.update_traces(texttemplate='%{value:.2f}%')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment