BAR chart with very thin bars (again)

Hi everyone again,
I haven’t been able to solve my problem yet:

When I create a bar chart in a time range, the bars are extremely thin and even if the time is very wide (months) they are not visible.

my simple code:

import pandas as pd
import plotly.express as px

df = pd.read_csv ('test.csv')

fig = px.bar(x=df.inicio, y=df.oee)
fig.show()

and this is the result >>

but I would like something like this >>

this is my test.csv >>

inicio,oee
2024-10-01 06:14:57,11.37
2024-10-01 09:18:48,57.19
2024-10-01 14:00:22,64.8
2024-10-02 06:23:29,60.3
2024-10-03 18:40:59,1.17
2024-10-04 09:13:01,69.84
2024-10-04 14:00:36,92.04
2024-10-04 16:09:08,76.85
2024-10-07 06:25:06,47.02
2024-10-07 14:18:47,91.39
2024-10-07 17:15:14,81.64
2024-10-08 06:02:50,78.33
2024-10-08 14:02:48,84.67
2024-10-08 19:38:38,79.32
2024-10-09 06:11:32,75.83
2024-10-09 13:40:35,20.07
2024-10-10 06:18:41,88.81
2024-10-11 06:11:21,28.82
2024-10-24 09:47:01,0.45
2024-10-24 14:00:40,5.02
2024-10-24 17:15:18,1.27
2024-11-05 15:22:33,53.79

Hey @gabino.alonso there is actually nothing you can do about it.

The problem here is, that you have time axis and each record is given as datetime. So what plotly does is that it shows your data as is, e.g. each record at the given time. If there is no record, there is no bar shown BUT the space on the axis is reserved.

What you will have to do is, prepare your data so that you have monthly records. How you do this depends on your goals- you could do a monthly mean- value or any other operation.

I answered quite often to these kind of questions, you could search the forum using “@aimped barplot” or similar.

thanks a lot @AIMPED

Unfortunately in some cases I can group weekly, monthly or yearly (like in the example I posted above) but in others I would like to be able to show the individual data.

please, any ideas to show the data in that case?

The only way I see is converting the time axis to categorical. You won’t have gaps but the graph might be harder to read due to missing time continuity.

See also: Timestamp xaxis bars thin when frequenxy become uneven - #2 by AIMPED

1 Like

OK, by defining the axis as categorical, the graph looks better but it is true that the X axis is a bit confusing with so many dates together.

How could I reduce how many ticks appear on the X axis? ¿Is it possible ?

for example >>

fig.update_layout(
    xaxis = dict(
        tickmode = 'linear',
        tick0=1,
        dtick=10
    )
)

is this the best way to do it ?

Thanks again

Sure: Search results for '@aimped tick' - Plotly Community Forum

For example: