Hi,
Here is my code:
import pandas as pd
from bokeh.io import output_notebook
from bokeh.models import ColumnDataSource
from bokeh.palettes import Bokeh8
from bokeh.plotting import figure, show
output_notebook()
data = {'date': ['2019-08-21',
'2019-09-02',
'2019-10-08',
'2019-11-01',
'2019-12-02',
'2020-01-02',
'2020-02-03',
'2020-03-02',
'2020-04-01',
'2020-05-06',
'2020-06-01',
'2020-07-01',
'2020-08-03',
'2020-09-01',
'2020-10-09',
'2020-11-02',
'2020-12-01',
'2021-01-04',
'2021-02-01',
'2021-03-01',
'2021-04-01',
'2021-05-06',
'2021-06-01',
'2021-07-01',
'2021-08-02',
'2021-09-01',
'2021-10-08',
'2021-11-01',
'2021-12-01',
'2022-01-04',
'2022-02-07',
'2022-03-01',
'2022-04-01',
'2022-05-05',
'2022-06-01',
'2022-07-01',
'2022-08-01',
'2022-09-01',
'2022-10-10',
'2022-11-01',
'2022-12-01',
'2023-01-03',
'2023-02-01',
'2023-03-01',
'2023-04-03',
'2023-05-04',
'2023-06-01',
'2023-07-03',
'2023-08-01',
'2023-09-01',
'2023-10-09',
'2023-11-01',
'2023-12-01',
'2024-01-02',
'2024-02-01',
'2024-03-01',
'2024-04-01',
'2024-05-06',
'2024-06-03',
'2024-07-01'],
'AAA': [38.548501355706556,
47.88238931293438,
68.1553420611671,
61.50283320583812,
33.696499165875956,
48.53466303474638,
51.65866576895849,
35.94462300035041,
63.34115752295874,
38.053395874857316,
29.833590569385297,
35.81508411386094,
40.35360896782375,
55.01534082331641,
80.67954996060007,
58.58564232425918,
54.47585528685438,
58.13707733614629,
51.357312548966846,
70.16268840811519,
61.20089201050857,
49.03330677664287,
52.17942347974438,
83.66722527892423,
38.105843161662726,
75.64412679447241,
74.30301115878919,
61.780178806274,
51.393361945047054,
64.96906799198881,
62.66255786417349,
75.60701635334077,
88.07239920879474,
63.153916709650105,
53.61965606935439,
79.2525179604621,
48.669474667731514,
60.597704217990525,
77.13653727931367,
65.80902804392302,
44.55475216447764,
54.16497425930436,
58.548028325588255,
49.83730249356159,
58.4205897753709,
44.405341658643245,
68.33270949809335,
72.48823353967538,
65.07616166557801,
57.97860226333309,
59.4732785338992,
71.26454893388495,
53.87553926642376,
45.04700046049706,
58.33088024170677,
51.190029673478335,
70.87724582614395,
62.81680164723068,
71.15831329606891,
75.26475547736815],
'BBB': [8.139767300098688,
6.379246258316986,
2.1397876745729327,
6.313706149780265,
15.098701765214418,
7.7490382079431805,
5.4726797054267635,
10.405559742857772,
2.986876875013502,
4.669670292672878,
7.534593039764434,
2.787635835876732,
12.118937055028901,
11.702122297877466,
2.8311461815551,
7.501054558928145,
3.6628575569337225,
8.239654014974363,
4.954066297839982,
2.083447797206059,
2.921473222095478,
5.137534178496049,
7.4582543454771635,
2.487862346261772,
3.531719837796348,
4.045284649360511,
1.7491675845137844,
3.3466232150159514,
4.840143341535361,
4.9917899774011145,
2.9899770578389937,
1.4854231702920762,
1.2255755891115165,
4.217472534148868,
2.243957753288968,
0.4403110214968118,
3.0835689089384903,
1.358814085474778,
1.32401918006161,
1.0346393179145001,
3.120564972772968,
3.491203517758961,
3.712850268944131,
4.988604699054436,
2.0553956517902305,
4.202924464452326,
5.646048112953468,
3.134292131741094,
2.3498068682642175,
3.9067051131274053,
3.468626646538365,
3.0846532069075083,
3.173765652430829,
4.656468001242938,
4.623212759956554,
4.605090488799595,
1.280748354179071,
4.3397422194240445,
4.245698908677754,
3.8753027881689577],
'CCC': [20.33619640167309,
21.839053421519523,
12.984387113073856,
17.037439813468634,
30.605229365542254,
20.129919416080906,
12.520100978849971,
18.799694232825843,
13.031657582957715,
34.57799846816344,
31.48451858867735,
21.398982791901407,
13.880594036442448,
16.359987287525573,
9.576664332282931,
18.982371743610287,
13.345619464746417,
11.382398022766575,
20.007435257759017,
7.9718626130888595,
14.16661151855533,
24.714673934208427,
14.467953604503977,
8.031869997453756,
14.341776606694575,
3.9418839554092053,
4.564235327892936,
7.486700473316088,
17.59347697991627,
12.473576787207497,
15.04802964216387,
10.192898968388441,
3.624050090172247,
11.076907165314589,
20.735698860060626,
11.139008999260989,
22.53908395429051,
9.363077384109896,
6.03765386981592,
7.858175963833991,
13.756148766416365,
12.991557327103815,
14.902961334387957,
12.92833522977923,
24.240163453474683,
7.470141718699687,
6.107220998859199,
7.9960017545868425,
11.332971437039006,
17.353084244155685,
21.790791062441144,
11.267577893518558,
26.875857820099007,
28.33963149477056,
12.295962219956854,
8.008082923230933,
11.498047450042755,
11.76844418653792,
10.034094521997764,
9.1514947839658],
'DDD': [31.070222323496406,
22.39069553159074,
15.20599254915021,
11.433062868932623,
16.63054694914773,
17.73999088605368,
11.536109040385249,
5.94744735263699,
8.215867704420134,
4.581166834727733,
13.661244663404798,
18.11867720632882,
18.918353106383204,
2.148206358192932,
2.129410525603654,
5.175257751107644,
10.375251539124092,
14.424937621863728,
11.772293710124755,
8.517816424911617,
10.006216206400245,
10.416508463177399,
12.89717856168254,
2.406021221902175,
20.90493365194458,
6.47207286470695,
6.725649596411921,
10.611713116209543,
13.269476983765664,
6.829261074943621,
3.838434899630019,
6.18507459115281,
2.123947386164871,
7.517018945207147,
8.06897785261463,
3.1154100903667428,
9.820284993268954,
7.9154055109322465,
4.907888529545782,
9.080783383593868,
16.237142357324924,
12.105998348145983,
11.276331206371859,
14.566789325570584,
8.095837208666254,
31.809784213595332,
4.449284501526217,
4.60115379026931,
10.00211500817693,
9.970006959423198,
7.297299021246675,
6.308433390618397,
6.519174687365989,
7.464980124896396,
6.143702102581181,
11.470405217149835,
10.742121711138521,
8.28345856640664,
6.051668845604065,
3.0236137587073757],
'EEE': [1.905312619025266,
1.508615475638359,
1.5144906020358848,
3.7129579619803543,
3.969022754219645,
5.846388455175859,
4.806725478330563,
3.0997337417149606,
2.3812000701467135,
3.232288993513746,
2.495291068737484,
3.3049396374412248,
1.4991101051932496,
1.3972568989086704,
1.300419913633468,
4.4854324561116625,
2.278505504418036,
3.2668163251214404,
3.378128590527836,
2.295955054159599,
4.279948757941389,
4.361435962058709,
2.9785614652010297,
0.7904443052775995,
9.881493651844071,
2.1654982104236375,
2.487593615611728,
8.654151321228905,
2.6928469132045016,
4.399264158891095,
8.041776030490281,
2.4059682971238145,
1.4876397054355845,
5.547905672493609,
7.290249721864706,
3.048220024855806,
4.246335920918918,
9.382396127074584,
5.046769737500849,
6.715388617357094,
5.688932277466472,
8.66045301040564,
3.317153951903546,
5.36844564972132,
1.8222360398536301,
5.028298589246329,
5.437604978634036,
7.770611578553886,
4.929525904497059,
5.693375496236237,
3.4575641074691306,
1.6911828946664809,
4.0572910223095,
5.394409600446887,
11.61615955606676,
13.620242330855644,
1.0446260006821124,
2.1788413865634495,
1.9883885592363564,
2.835818161097098],
'FFF': [0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
14.005719028048984,
25.802941929614015,
10.043240244503219,
14.885479536064869,
14.99076207003063,
18.574680414590883,
13.229396729128446,
13.377086334178953,
3.4828090863247776,
5.270241165983078,
10.341074161225704,
3.4935202035093234,
4.829537964020513,
7.375165079199482,
5.7836137148547895,
4.903330675320816,
7.83665860459272,
1.8025234144639548,
11.291889894154314,
6.094607058597666,
7.986408019845895,
5.5232303323366505,
8.177747791310704,
4.366037129787624,
5.206753693605719,
1.87468061662862,
1.6607404595406488,
6.506089290369925,
5.568879933344677,
1.5083032544691546,
8.600861432871042,
5.082503906682552,
2.3062030825683615,
7.191355638638881,
12.81952998752914,
5.0769150176586715,
6.625999371619594,
8.89162925149309,
2.7596235315099236,
4.641602012410844,
8.07035542708865,
1.453794632680936,
2.9886514432763236,
2.0350371068789914,
3.828881690130035,
4.385823310507942,
2.772365990386064,
6.796166343935865,
3.8825397757433975,
9.12145468824788,
2.4329337225366556,
8.013712864420087,
3.9894513471148487,
3.431229155470149],
'GGG': [0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
5.520836486697661,
1.0555964756182752,
3.7012256307610416,
1.5930646233191965,
1.641244569644223,
1.4332100100957361,
2.1819699387981877,
0.8140534357164931,
1.942343195903382,
1.6365264670296171,
2.18393469693455,
2.597402735618861,
2.0329460452204486,
1.9710028797802668,
2.21247081209762,
2.2489380030734702,
1.805647560780391,
1.980689682815763,
2.4725798094719904,
1.4962286490883918,
3.040390121980568,
6.300098767735419,
3.24092832119379,
2.310629034738645,
3.822929474012491,
3.508898519622578,
1.616675541184667,
3.4188933508197654,
2.6061543393343722,
2.4419073429522444,
1.9567764828450604,
2.5559125724925607,
3.3207676731684526,
3.0631888168454005,
0.6835589382754452,
1.9977803698961467,
2.7260055609848433,
2.301343974210285,
3.1075433439884845,
1.9846946782377872,
2.1242769352769364,
2.5989991294171886,
2.5323845213002922,
2.417785875222468]}
df = pd.DataFrame(data)
df.set_index("date", inplace=True)
source = ColumnDataSource(df)
p = figure(x_range=df.index.tolist(),
# x_axis_type="datetime",
tooltips=[("date", "@date"), ("name", "$name"), ("value", "@$name")], sizing_mode="stretch_width")
p.vbar_stack(df.columns.to_list(), x='date', color=Bokeh8[:len(df.columns)], source=data, legend_label=df.columns.to_list())
show(p)
Now, the problem is, if I don’t set “x_axis_type=‘datetime’” in figure parameter, the date appears crowded on the x-axis, like “figure 1”.
But, if I set "x_axis_type=‘datetime’, the date displaying is wrong, like “figure 2”.
How can I make the time scale of the X-axis automatically display the corresponding details as the zoom occurs, like “figure 3”, and when zoom-in, like “figure 4”: