Unable to see negative log axis Scatter plot

Hi,

I am trying to plot data sets which may/may not contain negative values on a log scale.

I am unable to see the point with negative value. Can you please help me out?

https://jsfiddle.net/5a52q1c9/1/

I’m not sure exactly what it should show.

You want the y-axis tick to span below y=0+ ?

yes… as of now the dataset is getting cut off… but if I use normal scale in my actual plot, the plot becomes cluttered.

I was wondering if there is a way to have the negative values also displayed using log scale

I see.

Our log axis don’t extend to negative numbers by design (consistent with Math.log(/* any negative number */) yielding NaN).

Other graphing libraries go around this problem by adding a different axis type often called symlog.

Someone did ask for symlog axes in plotly.js a few months ago. But it isn’t part of our short-term goals, so don’t expect that feature to be implemented anytime soon. You can subscribe to https://github.com/plotly/plotly.js/issues/221 for the latest development info.

You can use an approach in which you can take the absolute of negative number, calculating it’s log, and then plotting that point on the negative axis of the logarithmic scale. I hope this can be done. It is a much needed feature. Please comment.

2 Likes

It is not a priority for us at the moment unfortunately.

Hey, do we have an update for this?

Just to chime in here, one possible solution would be to simply color the positive and negative values differently and still have them on the same axis. This would be the simplest workaround. Another option would be to setup a two plot subplot figure and separately plot the positive and negative values on each, then simply reverse the log scale on the bottom plot to achieve the desired effect. I am not 100% sure if you can reverse the axis in a log plot though.

Hello,
I’m currently designing a dashboard highlighting data issues.
Often, I expect data to be mainly distributed, say, between 0 and 10. But, because of data/computation/etc related issues, i can have a few datapoint whose values goes to 100, or 1000. Also, values can be negative, in the same amplitude.

With linear axis,such extreme values “shrink” the yaxis, in a way that make all the normal values look like an horizontal line.

Log axis are convenient to address this point. However, negative values cannot be plotted, as raised above. Would be nice if we could get positive and negative log yaxis. Currently, if there are negative values, the line just go down, vertically.

Code snippet

import plotly.graph_objs as go
import pandas as pd
import plotly.io as pio
go.Figure(
    data=[
        go.Scatter(
            x=pd.to_datetime([20221231, 20230331, 20230630, 20230930, 20231231], format="%Y%m%d"), 
            y=[10, 20, 100, 30, -100]
        )
    ], 
    layout=go.Layout(template=pio.templates["plotly"], yaxis=dict(type="log"))
).show()

This topic has 4200 views as of June 2023, it looks like many users might be interested
image