Waffle chart: biểu đồ ô vuông thể hiện tỷ lệ, dùng pywaffle.Waffle.
- Tạo DataFrame: books = ['physics','chemistry','math','english','hindi'], price = [80,87,89,56,39].
- fig = plt.figure(FigureClass=Waffle, rows=5, values=df.price, labels=list(df.books)).
- show().
Ví dụ
import pandas as pd
import matplotlib.pyplot as plt
from pywaffle import Waffle
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
data = {'books': ['physics', 'chemistry', 'math', 'english', 'hindi'],
'price': [80, 87, 89, 56, 39] }
df = pd.DataFrame(data)
fig = plt.figure(
FigureClass=Waffle,
rows=5,
values=df.price,
labels=list(df.books) )
plt.show()
Kết quả
Waffle chart 5 hàng, mỗi ô đại diện cho giá trị price, màu và nhãn theo books.