Skip to content

Commit 94b8eac

Browse files
committed
add rounded bar examples
1 parent b4fb94a commit 94b8eac

File tree

1 file changed

+61
-3
lines changed

1 file changed

+61
-3
lines changed

doc/python/bar-charts.md

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.14.1
9+
jupytext_version: 1.16.1
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.8.8
23+
version: 3.10.11
2424
plotly:
2525
description: How to make Bar Charts in Python with Plotly.
2626
display_as: basic
@@ -480,6 +480,64 @@ fig.add_trace(go.Bar(x=years, y=[300, 400, 700],
480480
name='revenue'
481481
))
482482

483+
fig.show()
484+
```
485+
486+
### Rounded Bars
487+
488+
*New in 5.19*
489+
490+
You can round the corners on all bar traces in a figure by setting `barcornerradius` on the figure's layout. `barcornerradius` can be a number of pixels or a percentage of the bar width (using a string ending in %, for example "20%").
491+
492+
In this example, we set all bars to have a radius of 15 pixels.
493+
494+
```python
495+
import plotly.graph_objects as go
496+
from plotly import data
497+
498+
df = data.medals_wide()
499+
500+
fig = go.Figure(
501+
data=[
502+
go.Bar(x=df.nation, y=df.gold, name="Gold"),
503+
go.Bar(x=df.nation, y=df.silver, name="Silver"),
504+
go.Bar(x=df.nation, y=df.bronze, name="Bronze"),
505+
],
506+
layout=dict(
507+
barcornerradius=15,
508+
),
509+
)
510+
511+
fig.show()
512+
```
513+
514+
When you don't want all bar traces in a figure to have the same rounded corners, you can instead configure rounded corners on each trace using `marker.cornerradius`. In this example, which uses subplots, the first trace has a corner radius of 30 pixels, the second trace has a bar corner radius of 30% of the bar width, and the third trace has no rounded corners set.
515+
516+
```python
517+
import plotly.graph_objects as go
518+
from plotly.subplots import make_subplots
519+
from plotly import data
520+
521+
df = data.medals_wide()
522+
523+
fig = make_subplots(rows=1, cols=3, shared_yaxes=True)
524+
525+
fig.add_trace(
526+
go.Bar(x=df.nation, y=df.gold, name="Gold", marker=dict(cornerradius=30)), 1, 1
527+
)
528+
fig.add_trace(
529+
go.Bar(x=df.nation, y=df.silver, name="Silver", marker=dict(cornerradius="30%")),
530+
1,
531+
2,
532+
)
533+
534+
fig.add_trace(
535+
go.Bar(x=df.nation, y=df.bronze, name="Bronze"),
536+
1,
537+
3,
538+
)
539+
540+
483541
fig.show()
484542
```
485543

0 commit comments

Comments
 (0)