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?

4
  • what is the error that you are getting ? Commented Jul 20, 2019 at 9: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 Commented Jul 20, 2019 at 9:18
  • Did you try to copy-paste an example and adapt it to your needs? plot.ly/python/v3/tick-formatting Looks like there's plenty of flexible formatting options, including setting tick labels manually Commented Jul 20, 2019 at 9: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. Commented Jul 21, 2019 at 19:18

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.