'£ tick formatter in Plotly that respects negative values
Is there a way to format ticks in Plotly with a £ prefix and the negative sign in the proper place?
yaxis_tickformat='$,' works for $:
import plotly.express as px
fig = px.line(x=[1, 2], y=[3, -4])
fig.update_layout(yaxis_tickformat='$,')
fig.show()
fig.update_layout(yaxis_tickformat='£,')
fig.show()
And using tickprefix puts the - in the wrong place:
fig.update_layout(yaxis_tickprefix='£', yaxis_tickformat=',')
fig.show()
Notebook for reference.
Solution 1:[1]
You can set locale config for Your axis and specify currency symbol.
All options are described here.
So You can use yaxis_tickformat='$,', but You have to change currency to £.
Here is working code:
import plotly.express as px
fig = px.line(x=[1, 2], y=[3, -4])
fig.update_layout(yaxis_tickformat='$,')
config = {
'locales': {
'en': {
'format': {'currency': ["£", ""]}}
}
}
fig.show(config=config)
Assuming Your locale is en.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Domarm |


