3

Per the answer to Add Currency symbol in the y axis scale using plotly method in python, you can add a currency to a Python Plotly tick formatter via:

fig.update_layout(yaxis_tickprefix = '$', yaxis_tickformat = ',.')

However, this shows negative numbers as $-100 instead of -$100.

How can I format ticks to include $ and respect negative numbers?

Max Ghenis
  • 14,783
  • 16
  • 84
  • 132

1 Answers1

6

If you set the dollar sign in the tick format instead of the prefix, you will get the intended format.

import plotly.graph_objects as go
import numpy as np

fig = go.Figure(go.Scatter(
    x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
    y = np.random.randint(-20,20,12)
))
fig.update_layout(yaxis_tickformat='$,')#yaxis_tickprefix='$',

fig.show()

enter image description here

r-beginners
  • 31,170
  • 3
  • 14
  • 32
  • 1
    Is there some way to show GBP instead of USD? Tried setting Plotly locale config value to "en-GB" to no avail. – N.Woodruff Mar 01 '22 at 14:59
  • @N.Woodruff I filed https://stackoverflow.com/questions/71311180/%c2%a3-tick-formatter-in-plotly-that-respects-negative-values for £ – Max Ghenis Mar 01 '22 at 15:54