Home > Software engineering >  plotly express: yaxis from string to numeric
plotly express: yaxis from string to numeric

Time:08-07

I have the following table:

enter image description here

I need to draw line charts of both dogs and cats on the same graph. When writing:

fig = px.line(df2, x='Year', y=['dogs','cats'])

I get this chart: enter image description here which obviously not what I want:

  1. it shows the number on Y Axis as strings and not as real numbers. As such, the negative numbers are also not ordered correctly.
  2. it does not equaly divide the ticks.

How do I read those numbers as floats, and at the same time, divide the ticks to have integer values, of let's say 500, 1000, 1500, etc?

CodePudding user response:

Look in your dataframe, the values of dogs and cats have "comma", hence they are being treated as string, remove them and your desired graph will be automatically created like this: enter image description here

  • Related