You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/python/bar-charts.md
+152Lines changed: 152 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -315,6 +315,158 @@ fig.update_layout(
315
315
fig.show()
316
316
```
317
317
318
+
### Control Bar Position in Different Subplots
319
+
320
+
To control bars positional range among several subplots, set the same axes to the same [alignmentgroup](https://plot.ly/python/reference/#bar-alignmentgroup). In the following example we have two subplots sharing an x axis with two bar traces (trace0, trace1) on the top, and one bar trace (trace2) on the bottom, that all are aligned by setting the same `alignmentgroup`.
321
+
You also can line up bars of the same positional coordinate by setting [offsetgroup](https://plot.ly/python/reference/#bar-offsetgroup).
322
+
323
+
```python
324
+
import plotly.graph_objects as go
325
+
326
+
fig = go.Figure(go.Bar(
327
+
alignmentgroup="a",
328
+
offsetgroup=0,
329
+
x= [1,2,3],
330
+
y= [2,3,4],
331
+
xaxis='x',
332
+
yaxis='y'))
333
+
334
+
fig.add_trace(go.Bar(
335
+
alignmentgroup="a",
336
+
offsetgroup=1,
337
+
x= [1,2,3],
338
+
y= [2,3,4],
339
+
xaxis='x',
340
+
yaxis='y'))
341
+
342
+
fig.add_trace(go.Bar(
343
+
alignmentgroup="a",
344
+
offsetgroup=1,
345
+
x= [1,2,3],
346
+
y= [2,3,4],
347
+
xaxis='x',
348
+
yaxis='y2'))
349
+
350
+
351
+
fig.update_layout(
352
+
xaxis= {
353
+
'anchor': 'y'},
354
+
yaxis2= {
355
+
'___domain': [.55,1],
356
+
'anchor': 'x'},
357
+
yaxis= {
358
+
'___domain': [0,.45],
359
+
'anchor': 'x'})
360
+
361
+
fig.show()
362
+
```
363
+
364
+
### Offsetgroup vs. Alignmentgroup
365
+
366
+
```python
367
+
import plotly.graph_objects as go
368
+
369
+
fig = go.Figure(go.Bar(
370
+
alignmentgroup="a",
371
+
offsetgroup=0,
372
+
x= [1,2,3],
373
+
y= [2,3,4],
374
+
xaxis='x',
375
+
yaxis='y'))
376
+
377
+
fig.add_trace(go.Bar(
378
+
alignmentgroup="a",
379
+
offsetgroup=1,
380
+
x= [1,2,3],
381
+
y= [2,3,4],
382
+
xaxis='x',
383
+
yaxis='y'))
384
+
385
+
fig.add_trace(go.Bar(
386
+
alignmentgroup="a",
387
+
offsetgroup=2,
388
+
x= [1,2,3],
389
+
y= [2,3,4],
390
+
xaxis='x',
391
+
yaxis='y2'))
392
+
393
+
fig.add_trace(go.Bar(
394
+
alignmentgroup="a",
395
+
offsetgroup=0,
396
+
x= [1,2,3],
397
+
y= [2,3,4],
398
+
xaxis='x2',
399
+
yaxis='y3'))
400
+
401
+
fig.add_trace(go.Bar(
402
+
alignmentgroup="b",
403
+
offsetgroup=1,
404
+
x= [1,2,3],
405
+
y= [2,3,4],
406
+
xaxis='x2',
407
+
yaxis='y4'))
408
+
409
+
fig.add_trace(go.Bar(
410
+
alignmentgroup="a",
411
+
offsetgroup=1,
412
+
x= [1,2,3],
413
+
y= [2,3,4],
414
+
xaxis='x2',
415
+
yaxis='y3'))
416
+
417
+
fig.add_trace(go.Bar(
418
+
alignmentgroup="a",
419
+
offsetgroup=0,
420
+
x= [1,2,3],
421
+
y= [2,3,4],
422
+
xaxis='x3',
423
+
yaxis='y5'))
424
+
425
+
fig.add_trace(go.Bar(
426
+
alignmentgroup="a",
427
+
offsetgroup=1,
428
+
x= [1,2,3],
429
+
y= [2,3,4],
430
+
xaxis='x3',
431
+
yaxis='y6'))
432
+
433
+
fig.add_trace(go.Bar(
434
+
alignmentgroup="a",
435
+
offsetgroup=1,
436
+
x= [1,2,3],
437
+
y= [2,3,4],
438
+
xaxis='x3',
439
+
yaxis='y5'))
440
+
441
+
fig.update_layout(
442
+
xaxis= {
443
+
'___domain': [0, .35],
444
+
'anchor': 'y',
445
+
'title': "=alignment<br>≠offset"},
446
+
xaxis2= {
447
+
'___domain': [.42, .65],
448
+
'title': "≠alignment<br>=offset",
449
+
'anchor': 'y'
450
+
},
451
+
xaxis3= {
452
+
'___domain': [.72, 1],
453
+
'title': "=alignment<br>=offset",
454
+
'anchor': 'y'
455
+
},
456
+
yaxis2= {
457
+
'___domain': [.55,1],
458
+
'anchor': 'x'},
459
+
yaxis= {
460
+
'___domain': [0,.45],
461
+
'anchor': 'x'},
462
+
yaxis3= {'___domain': [.55,1], 'anchor': 'x2'},
463
+
yaxis4= {'___domain': [0, .5], 'anchor': 'x2'},
464
+
yaxis5= {'___domain': [.55, 1], 'anchor': 'x3'},
465
+
yaxis6= {'___domain': [0, .5], 'anchor': 'x3'})
466
+
467
+
fig.show()
468
+
```
469
+
318
470
### Bar Chart with Relative Barmode
319
471
320
472
With "relative" barmode, the bars are stacked on top of one another, with negative values
0 commit comments