Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdcd253e

Browse files
committed
Simplify "Grouped bar chart with labels" using grouped_bar()
1 parent13105c8 commitdcd253e

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

‎galleries/examples/lines_bars_and_markers/barchart.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# data from https://allisonhorst.github.io/palmerpenguins/
1111

1212
importmatplotlib.pyplotasplt
13-
importnumpyasnp
1413

1514
species= ("Adelie","Chinstrap","Gentoo")
1615
penguin_means= {
@@ -19,22 +18,15 @@
1918
'Flipper Length': (189.95,195.82,217.19),
2019
}
2120

22-
x=np.arange(len(species))# the label locations
23-
width=0.25# the width of the bars
24-
multiplier=0
25-
2621
fig,ax=plt.subplots(layout='constrained')
2722

28-
forattribute,measurementinpenguin_means.items():
29-
offset=width*multiplier
30-
rects=ax.bar(x+offset,measurement,width,label=attribute)
31-
ax.bar_label(rects,padding=3)
32-
multiplier+=1
23+
res=ax.grouped_bar(penguin_means,tick_labels=species,group_spacing=1)
24+
forcontainerinres.bar_containers:
25+
ax.bar_label(container,padding=3)
3326

34-
# Add some text for labels, title and custom x-axis tick labels, etc.
27+
# Add some text for labels, title, etc.
3528
ax.set_ylabel('Length (mm)')
3629
ax.set_title('Penguin attributes by species')
37-
ax.set_xticks(x+width,species)
3830
ax.legend(loc='upper left',ncols=3)
3931
ax.set_ylim(0,250)
4032

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp