Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- line color
- Else
- start exercise
- variables
- Text mining
- continue
- train/test
- line width
- polynomial regression
- For loops
- SQL
- self parameter
- MySQL
- pie charts
- __init__
- iterates
- Python
- matplotlib.pyplot
- PROJECT
- PANDAS
- error
- data distribution
- Text Analytics
- Default X points
- machine learning
- matplotlib
- AS
- multiple lines
- break
- Github
Archives
- Today
- Total
Data Science Explorer
Matplotlib Bars 본문
반응형
- Creating bars
Use bar() function to draw the bar graph.
Example
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["Grace", "Momo", "Anas", "David"])
y = np.array([3, 8, 1, 10])
plt.bar(x,y)
plt.show()
Result
- Horizontal bars
Use barh() to have your graph displayed horizontally.
Example
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["A", "B", "C", "D"])
y = np.array([8,1,2,6])
plt.barh(x, y)
plt.show()
Result
Bar Color
You can adjust the color by using argument c.
Example
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["A", "B", "C", "D"])
y = np.array([3, 8, 1, 10])
plt.bar(x, y, color = "red")
plt.show()
Result
- Bar Width
Use argument width to adjust the width.
Example
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["Grace", "Dan", "Pearl", "Sara"])
y = np.array([8, 8, 2, 10])
plt.bar(x, y, width = 0.2)
plt.show()
Result
- Bar Height
For horizontal bars (barh), it takes the keyword height to set the height of the bars instead of width.
Example
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["Grace", "Dan", "Pearl", "Sara"])
y = np.array([8, 8, 2, 10])
plt.barh(x, y, height = 0.2)
plt.show()
Result
'Python' 카테고리의 다른 글
Matplotlib Pie Charts (0) | 2023.11.11 |
---|---|
Matplotlib Histograms (0) | 2023.11.10 |
Matplotlib Scatter (0) | 2023.11.08 |
Matplotlib Subplot (0) | 2023.11.07 |
Matplotlib: Matplotlib Adding Grid Lines (0) | 2023.11.06 |