Gibberish / malformed negative y-axis values in plotly charts in python

Im trying to plot a bar plot in plotly that is representing net-gains (will have positive and negative bar values). But somewhat the negative values in the y-axis are being represented in gibberish. I tried several things, including using update_layout function, but nothing seems to work. Im using the make_subplots function because i want to plot multiple viz on one figure.

Im using databricks for this code.
Attaching my code and viz output:

net_gains = pd.DataFrame()
net_gains["general_net_gain"] = [-2,2,-1,2]


fig = plotly.subplots.make_subplots(rows=1, cols=1)
fig.add_bar(x=net_gains.index, y=net_gains["general_net_gain"], row=1, col=1)
fig.update_layout(height=400,width=500,showlegend=True)

[![Viz output][1]][1]

Screen Shot 2023-01-25 at 14.46.44

HI @harrykane welcome to the forums.

I can’t reproduce this and never have seen this before. Did you find a way to solve it?

Hi, seems that you are not the only one with this issue:

Which plotly version are you using?

@adamschroeder

@adamschroeder im using 5.12.0 plotly version

hi @harrykane
I’m not able to recreate your issue either. I’m using plotly 5.12.0, and I’ve tried this code:

from plotly.subplots import make_subplots
import plotly.graph_objects as go
import plotly

fig = plotly.subplots.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=600, width=800)
fig.show()

which makes this:

I’ve also tried this code:

from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(rows=1, cols=2)

fig.add_trace(
    go.Scatter(x=[1, 2, 3], y=[-4, 5, -6]),
    row=1, col=1
)

fig.add_trace(
    go.Scatter(x=[20, 30, 40], y=[50, -60, 70]),
    row=1, col=2
)

fig.update_layout(height=600, width=800, title_text="Side By Side Subplots")
fig.show()

Can you please share a sample of your data and full code that was used to create the problematic charts.

The following code duplicates the problem for me:

#!/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

1 Like

I’ve reported this as a bug in:

Gibberish / malformed / strange negative y-axis values Β· Issue #4118 Β· plotly/plotly.py (github.com)