1

I am planning to use plotly and plot value from a number to .k, for example, the value showed on the chart is like 8247294, and I want it to show like 8.25M

I tried something like this:

x = [x for x in range(1,len(table))] #date
y = table['revenue'].values.tolist()

fig = go.Figure(go.Scatter(x=x, y=y,text=y,mode="lines+markers+text",
                line=dict(color='firebrick', width=4)))
fig.update_layout(width=900,height=650)

fig.update_layout(
      tickformat='k') 

It is not working.So what's the correct way of doing it?

qwer1234
  • 257
  • 4
  • 9
  • what is the error that you are getting ? – Madhur Yadav Jul 20 '19 at 09:15
  • Sorry I didn't explain it clearly. the value showed on the chart is like 8247294, and I want it to show like 8.25M – qwer1234 Jul 20 '19 at 09:18
  • Did you try to copy-paste an example and adapt it to your needs? https://plot.ly/python/v3/tick-formatting/ Looks like there's plenty of flexible formatting options, including setting tick labels manually – Yuri Feldman Jul 20 '19 at 09:31
  • At the moment there's no functionality for processing the data passed to `text`: it is displayed as-is. An upcoming version of Plotly.py will support this, however, as it is being implemented in the underlying Plotly.js library this week. – nicolaskruchten Jul 21 '19 at 19:18

1 Answers1

0
import plotly.graph_objs as go
import pandas as pd

data = {
    'date': pd.date_range(start='2023-01-01', periods=10),
    'revenue': [1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000]
}

table = pd.DataFrame(data)

x = table['date']  # date
y = table['revenue'].values.tolist()

fig = go.Figure(go.Scatter(x=x, y=y, mode="lines+markers+text",
                           line=dict(color='firebrick', width=4)))

fig.update_layout(
    yaxis=dict(
        tickformat=".2s"            #<---------- Use this format
    )
)

fig.show()

enter image description here

Hamzah
  • 8,175
  • 3
  • 19
  • 43