본문 바로가기
파이썬. 데이터분석/Matplotlib

matplotlib : 막대그래프 두께width 조절

by 한국수달보호협회장 2022. 10. 4.

 

 

https://www.python-graph-gallery.com/5-control-width-and-space-in-barplots

 

Control width and space in barplots using matplotlib | The Python Graph Gallery

Controlling the width of bars and space between bars in a barplot using matplotlib

www.python-graph-gallery.com

 

# library
import matplotlib.pyplot as plt
 
# create dataset
height = [3, 12, 5, 18, 45]
bars = ('A', 'B', 'C', 'D', 'E')

# Choose the width of each bar and their positions
width = [0.1, 0.2, 3, 1.5, 0.3]
x_pos = [0, 0.3, 2, 4.5, 5.5]
 
# Make the plot
plt.bar(x_pos, height, width=width)

# Create names on the x-axis
plt.xticks(x_pos, bars)
 
# Show graphic
plt.show()