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

Gibberish / malformed / strange negative y-axis values #4118

Closed
valankar opened this issue Mar 21, 2023 · 6 comments
Closed

Gibberish / malformed / strange negative y-axis values #4118

valankar opened this issue Mar 21, 2023 · 6 comments

Comments

@valankar
Copy link

#!/usr/bin/env python3
"""Test negative bug."""

from plotly.subplots import make_subplots

fig = make_subplots(rows=1, cols=1)
fig.add_bar(x=[1, 2, 3], y=[-4, 5, -6], row=1, col=1)
fig.update_layout(height=400, width=500, showlegend=True)

with open('web/negative.html', 'w', encoding='utf-8') as index_file:
    index_file.write(fig.to_html(full_html=False))

This results in:

neg

When I change to full_html=True, it works properly:

pos

This seems to be a recent bug because it worked fine before I upgraded Plotly. I’m using this version from conda-forge:

plotly 5.13.1 pyhd8ed1ab_0 conda-forge

More details on this issue:

https://community.plotly.com/t/gibberish-malformed-negative-y-axis-values-in-plotly-charts-in-python/71924/1

@AaronStiff
Copy link
Contributor

@alexcjohnson is this related to the changes to write_html made in 5.13.0 (#4019) or this something different?

@nicolaskruchten
Copy link
Contributor

I believe this will be fixed when we merge #4114

@nicolaskruchten
Copy link
Contributor

Or rather, the same fix is required. Recent versions of Plotly.js contain UTF-8 characters and hence must specify the encoding when loading the library.

@valankar
Copy link
Author

It seems like this is fixed now?

rl-utility-man added a commit to rl-utility-man/plotly.py that referenced this issue Mar 4, 2024
I followed this example and got nonsense characters instead of negative signs because I failed to specify UTF-8 encoding, as discussed in plotly#4118
@RomFR57
Copy link

RomFR57 commented Mar 25, 2024

It worked for me when i added this line to the html file :

<meta charset="utf-8">

Python code :

import plotly.offline as offline

template = """
<meta charset="utf-8">
<head>
<body style="background-color:#111111;">
</head>
<body>
{plot_div:s}
</body>""".format(plot_div=offline.plot(fig, config=config, output_type='div'))
with open('fig.html', 'w', encoding="utf-8") as fp:
    fp.write(template)

@Coding-with-Adam
Copy link
Contributor

Thanks for the advice, @RomFR57 .
This seems to be fixed to me as well. I also tried the code provided by the original poster and it works.

Closing this issue for now. If we rediscover a bug, I can reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants