How to change the Y-Axis in Plotly to go from scientific to exponential or plain?

1.7k views Asked by At

Ive seen many different answers, but need one specifically for the use of Plotly in Python....my code is below, but the Y axis doesn't come back in basic decimal points (I believe it come back in some micro format where instead of .000258 it will show 258.XXX)

 floki_ohlc = df.iplot(kind = "ohlc",fill = True, colorscale = "rdylbu", theme = "solar",
                  title = "FLOKI INU/USDT", xTitle = "Time", yTitle = "Price (USD)")

And I cant find anything in the documentation about changing the values, only the titles.

Thanks in advance@

1

There are 1 answers

1
Kat On

I'm guessing you're using express. I used the diamonds dataset from the R library ggplot2 for the plot.

It can be done in Python when you create the graph. Since I don't have your data, I've made a few examples and what changes and how it changes when I use it.

Plotly formatting uses D3. You can read more about that here.

import pandas as pd
pd.options.plotting.backend = "plotly"

diam_py = r.diamonds

df = pd.DataFrame(diam_py)

fig = df.plot.bar(x = "color", 
                  y = "price", 
                  color = "cut",
                  template = "simple_white",
                  barmode = "group")
fig.show()

fig.update_yaxes(tickformat=",.0f").show() # use thousand comma; round to whole number
fig.update_yaxes(tickformat="none").show() # show number as is
fig.update_yaxes(tickformat=",.0s").show() # SI prefix with 0 significant digits
fig.update_yaxes(tickformat="#x").show()   # prefixed lowercase hexidecimal 
# more details at https://github.com/d3/d3-format

The figures are in the order in which they appear in the code.

Default y-axis formatting

default

Use commas at the thousands & round to the whole number

Big mark and rounded

Remove all formatting—show as is in the data

No formatting

SI prefix with no significant digits (M for millions here)

SI prefix, with no significant digits

Hexidecimal formatting...in case binary is of interest

hexidecimal