Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scatter graph's Y axis always starting at 0

Tags:

python

plotly

I'm getting a Plotly issue.

I need my scatter graph's Y axis to always start at 0. The graph object is created and returned by an auxiliary function as follows:

[go.Scatter(x=time_index,
            y=self.data,
            name=self.data.name
              )]

And then this function returns it and there is another function that actually generates the graph in a dash object, because it is a web application that I need this for.

The thing is that I need to know if there is some attribute inside the go.Scatter object that I can edit in order to always get the Y axis to start at 0.

As you can see in the image below, the Y axis starts at 10k rather than at 0.

enter image description here

like image 798
HRDSL Avatar asked Sep 12 '19 12:09

HRDSL


People also ask

Do scatter plots always start the Y axis at 0?

Scatter plots use the same positional method of encoding each data point, but I have never heard anyone say that scatterplot axes should start at zero. In most cases, a zero-based axis makes sense, but it ultimately depends on the data and visualization used.

Why should the Y axis start from 0 in a bar chart?

Data viz nerds agree bar charts must start at zero.The bars in a bar chart encode the data by their length, so if we truncate the length by starting the axis at something other than zero, we distort the visual in a bad way.


1 Answers

As far as I know it's not possible to set this property in the go.Scatter object directly, but there is a layout parameter called rangemode wich you can set to 'tozero':

fig.update_yaxes(rangemode="tozero")

like image 150
Pirmin Avatar answered Oct 12 '22 15:10

Pirmin