Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Currency symbols on d3 formats exporting to an image not available (only $) #191

Open
jesusenlanet opened this issue Jul 13, 2023 · 4 comments
Labels
bug something broken P3 not needed for current cycle

Comments

@jesusenlanet
Copy link

Hi,

I am having problems when exporting a figure to static image.

I need to be able to use the monetary capabilities of the d3 format since the same chart should show one monetary symbol or another depending on some input data, but the only currency symbol that works exporting the figure to a static image is $, as I understand to use a different currency symbol is needed to modify the locales config.

Another solution is using a prefix on the axis, the two most relevant documentation links I have found would be these two, one talks about stopping using xaxis_tickprefix and yaxis_tickprefix due to the symbol position problem and links to the second link, where it gives as a solution the use of config, argument not available in plotly.io.write_image.

  1. https://stackoverflow.com/questions/71303258/tick-formatter-in-plotly-that-respects-negative-values
  2. https://stackoverflow.com/questions/71311180/%c2%a3-tick-formatter-in-plotly-that-respects-negative-values

According to what I have studied to solve my problem this would be by passing a config to the show method specifying the appropriate locales.

The problem is that to export to an image I must use the plotly.io.write_image method, which does not accept any config that I would use to set the appropriate currency symbol for each occasion.

The current solution I have found is using xaxis_tickprefix and yaxis_tickprefix, but it has the drawback of badly positioning the currency sign and symbol with negative amounts, e.g. € -100 instead of -€100, for the case of a particular locale.

Since I use Kaleido, it came to my mind that maybe it could be done through it, but I haven't found anything.

Any help? I'm not sure if I'm missing something or maybe it's more of a new feature.

Thank you very much.

@empet
Copy link

empet commented Jul 13, 2023

Setting yaxis_tickvals and yaxis_ticktext you get the desired ticklabels:

import plotly.express as px
import numpy as np
fig = px.line(x=[1, 2], y=[3, -4])
tickvals= np.arange(-4, 4, 1.5)
fig.update_layout(width=600, height=350, 
                  yaxis_ticktext=[f"\u00A3{val}" if val>=0 else f"-\u00A3{abs(val)}" 
                                  for val in tickvals],
                  yaxis_tickvals=tickvals)

pounds-as-ticks

@jesusenlanet
Copy link
Author

Many thanks @empet, it's an interesting workaround that I am already testing.

It would be great to have the possibility to use a config object like in the show method to handle this all via locales.

The position of some symbols is different depending on the country, for example in Spain (10,42€) (even in some countries the currency symbol is used as decimal separator (10$42, but this format is not available on d3)).

@jesusenlanet
Copy link
Author

Setting yaxis_tickvals and yaxis_ticktext you get the desired ticklabels:

import plotly.express as px
import numpy as np
fig = px.line(x=[1, 2], y=[3, -4])
tickvals= np.arange(-4, 4, 1.5)
fig.update_layout(width=600, height=350, 
                  yaxis_ticktext=[f"\u00A3{val}" if val>=0 else f"-\u00A3{abs(val)}" 
                                  for val in tickvals],
                  yaxis_tickvals=tickvals)

pounds-as-ticks

I tested this solution and for my needs is not enough, I need to stitch to the d3 format specification:
https://github.com/d3/d3-format#api-reference

This solution works if I wouldn't need to use the d3 format but I need it.
Many thanks for your help.

@gvwilson gvwilson transferred this issue from plotly/plotly.py Jul 11, 2024
@gvwilson gvwilson self-assigned this Jul 26, 2024
@gvwilson
Copy link
Collaborator

Thanks for your interest in Kaleido. We are currently working on an overhaul that might address your issue - we hope to have news in a few weeks and will post an update then. Thanks - @gvwilson

@gvwilson gvwilson removed their assignment Aug 3, 2024
@gvwilson gvwilson added bug something broken P3 not needed for current cycle labels Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P3 not needed for current cycle
Projects
None yet
Development

No branches or pull requests

3 participants