Cố gắng làm cho chiếc bánh lớn hơn. Nhìn vào các tài liệu, và những nơi khác, nó nói để đặt bán kính. Có vẻ như không có vấn đề gì tôi đặt trong bán kính thì không có sự gia tăng nào. Tôi đang đăng mã đầy đủ và hình ảnh mà nó tạo ra.
import matplotlib.pyplot as plt
def autopct_generator[limit]:
"""Remove percent on small slices."""
def inner_autopct[pct]:
return ['%.2f%%' % pct] if pct > limit else ''
return inner_autopct
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs', 'Test', 'Test2', 'Test3', \
'Test4', 'Test5', 'Test6', 'Test7', 'Test8', 'Test9', 'Test10', \
'Test11', 'Test12', 'Test13', 'Test14'
sizes = [15, 30, 45, 10, 10, 24, 13, 18, 28, 20, 13, 15, 5, 1, 18, 10,
10, 10]
NUM_COLORS = len[sizes]
fig1, ax1 = plt.subplots[figsize=[6, 5]]
# set color theme
# //matplotlib.org/api/pyplot_summary.html#colors-in-matplotlib
theme = plt.get_cmap['bwr']
ax1.set_color_cycle[[theme[
1. * i / NUM_COLORS] for i in range[NUM_COLORS]]]
box = ax1.get_position[]
ax1.set_position[[box.x0, box.y0, box.width * 1.3, box.height]]
_, _, autotexts = ax1.pie[
sizes, autopct=autopct_generator[7], startangle=90, radius=1.8 * 1000]
for autotext in autotexts:
autotext.set_weight['bold']
ax1.axis['equal']
total = sum[sizes]
plt.legend[
loc='upper left',
labels=['%s, %1.1f%%' % [
l, [float[s] / total] * 100] for l, s in zip[labels, sizes]],
prop={'size': 12},
bbox_to_anchor=[0.0, 1],
bbox_transform=fig1.transFigure
]
# fig1.set_size_inches[18.5, 10.5]
fig1.savefig['chart.png']
Làm một lát bật ra. Bạn có thể thực hiện một hoặc nhiều lát cắt biểu đồ hình tròn bằng tùy chọn Explode. ....
Xoay biểu đồ hình tròn. Bạn có thể xoay biểu đồ hình tròn bằng cách đặt một strartangle. ....matplotlib pie chart? To draw pie char use plt.pie[] function. The matplotkib plt.pie[] function help to plot pie chart of given numeric data with labels. It also support different parameters which help to show better.
Hiển thị tỷ lệ phần trăm. ....
import matplotlib.pyplot as plt
Tùy chỉnh màu sắc. ....
plt.pie[[1]] # Plot pie chart of value [1] plt.show[] # To show Pie chart
Đầu ra >>>
Biểu đồ hình tròn Matplotlib
classes = ["Python", 'R', 'Machine Learning', 'Artificial Intelligence', 'Data Sciece'] class1_students = [45, 15, 35, 25, 30]
Trong blog này, chúng tôi sẽ làm việc về cách vẽ biểu đồ hình tròn matplotlib? Để vẽ Pie Char sử dụng hàm plt.pie []. Chức năng matplotkib plt.pie [] giúp vẽ biểu đồ hình tròn của dữ liệu số nhất định với các nhãn. Nó cũng hỗ trợ các thông số khác nhau giúp hiển thị tốt hơn.
plt.pie[class1_students, labels = classes] plt.show[]
Đầu ra >>>
Biểu đồ biểu đồ biểu đồ matplotlib
Hình 1.1 - Biểu đồ hình tròn đơn giản Matplotlib plt.pie[
[‘x’,
‘explode=None’,
‘labels=None’,
‘colors=None’,
‘autopct=None’,
‘pctdistance=0.6’,
‘shadow=False’,
‘labeldistance=1.1’,
‘startangle=None’,
‘radius=None’,
‘counterclock=True’,
‘wedgeprops=None’,
‘textprops=None’,
‘center=[0, 0]’,
‘frame=False’,
‘rotatelabels=False’,
‘*’,
‘data=None’],
]
Nhập bộ dữ liệu
explode : array-like, optional, default: None
labels : list, optional, default: None
colors : array-like, optional, default: None
autopct : None [default], string, or function, optional
pctdistance : float, optional, default: 0.6
shadow
: bool, optional, default: False
labeldistance : float, optional, default: 1.1
startangle : float, optional, default: None
radius : float, optional, default: None
counterclock : bool, optional, default: True
wedgeprops : dict, optional, default: None
—- example, you can pass in wedgeprops = {‘linewidth’: 3}
textprops : dict, optional, default: None
center : list of float, optional, default: [0, 0]
frame : bool, optional, default: False
rotatelabels :
bool, optional, default: False
Vẽ biểu đồ hình tròn bằng cách sử dụng các tham số khác nhau.
explode = [0.03,0,0.1,0,0] # To slice the perticuler section colors = ["c", 'b','r','y','g'] # Color of each section textprops = {"fontsize":15} # Font size of text in pie chart plt.pie[class1_students, # Values labels = classes, # Labels for each sections explode = explode, # To slice the perticuler section colors =colors, # Color of each section autopct = "%0.2f%%", # Show data in persentage for with 2 decimal point shadow = True, # Showing shadow of pie chart radius = 1.4, # Radius to increase or decrease the size of pie chart startangle = 270, # Start angle of first section textprops =textprops] plt.show[] # To show pie chart only
Đầu ra >>>
Vẽ biểu đồ hình tròn bằng cách sử dụng huyền thoại - plt.legend []
explode = [0.03,0,0.1,0,0] # To slice the perticuler section colors = ["c", 'b','r','y','g'] # Color of each section textprops = {"fontsize":15} # Font size of text in pie chart plt.pie[class1_students, # Values labels = classes, # Labels for each sections explode = explode, # To slice the perticuler section colors =colors, # Color of each section autopct = "%0.2f%%", # Show data in persentage for with 2 decimal point shadow = True, # Showing shadow of pie chart radius = 1.4, # Radius to increase or decrease the size of pie chart startangle = 270, # Start angle of first section textprops =textprops] plt.legend[] # To show legend plt.show[] # To show pie chart only
Đầu ra >>>
Sơ đồ biểu đồ hình tròn sử dụng nhiều tham số hơn ở trên và chiều rộng = 1.
plt.figure[figsize = [3,2]] wedgeprops = {"linewidth": 4, 'width':1, "edgecolor":"k"} # Width = 1 plt.pie[ class1_students, labels = classes, explode = explode, colors = colors, autopct = "%0.2f%%", pctdistance = 0.6, shadow =True, labeldistance = 1.6, startangle = 270, radius = 1, counterclock = True, wedgeprops = wedgeprops, textprops = textprops, center=[2, 3], frame=True, rotatelabels=True ] plt.show[]
Đầu ra >>>
Vẽ biểu đồ hình tròn bằng cách sử dụng huyền thoại - plt.legend []
Sơ đồ biểu đồ hình tròn sử dụng nhiều tham số hơn ở trên và chiều rộng = 1.
import numpy as np plt.figure[figsize=[7,4]] #plt.figure[figsize=[16,9] colors = ['r','w','r','w','r','w','r','w','r','w','r','w','r','w','r','w','r','w','r','w'] labels = np.ones[20] #labels = [1.0,1.0,1.0,1.0,1.0,.........,1.0] plt.pie[[1], colors="k", radius = 2.05] plt.pie[labels, colors=colors, radius = 2.0] plt.pie[[1], colors="g", radius = 1.8] plt.pie[[1], colors="y", radius = 1.6] plt.pie[[1], colors="c", radius = 1.3] plt.pie[[1], colors="b", radius = 1.1] plt.pie[[1], colors="m", radius = 0.9] plt.pie[[1], colors="b", radius = 0.31] plt.pie[labels, colors=colors, radius = 0.3] plt.pie[[1], colors="w", radius = 0.2] plt.pie[[1], colors="k", radius = 0.1] plt.show[]
Đầu ra >>>
Sự kết luận
Trong blog & nbsp; matplotlib plt.pie Biểu đồ, chúng tôi tìm hiểu cách vẽ các biểu đồ một và nhiều hình tròn với một ví dụ thời gian thực bằng cách sử dụng & nbsp; plt.pie [] & nbsp; phương thức. Cùng với phương pháp khác nhau được sử dụng và tham số khác nhau. Chúng tôi khuyên bạn nên làm cho bàn tay của bạn bị bẩn với từng tham số của các phương thức trên. Đây là thực hành mã hóa tốt nhất. Sau khi hoàn thành & nbsp; hướng dẫn matplotlib & nbsp; nhảy trên Seaborn.matplotlib plt.pie chart blog, we learn how to plot one and multiple pie charts with a real-time example using the plt.pie[] method. Along with that used different method and different parameter. We suggest you make your hand dirty with each and every parameter of the above methods. This is the best coding practice. After completion of the matplotlib tutorial jump on Seaborn.
Tải xuống tệp Jupyter của mã nguồn biểu đồ thanh matplotlib
Truy cập trang web chính thức của matplotlib.org