最近在写一篇论文,发现python作图居然也挺好看的,以前只知道PPT,VISIO,MATLAB等等,现在发现python这些个绘图包真的越来越丰富了,会议画出非常精美的图,甚至GIF,动态词云等等,可以去深入学习学习。对了,对于论文,还可以使用导出latex文件的图,或者eps矢量图这样的格式文件,这样的话在文档中可能会更加清晰。
另外这个博主写的挺好的~
https://www.cnblogs.com/zhhfan/p/9971757.html
https://www.cnblogs.com/zhhfan/p/9964805.html
https://www.cnblogs.com/zhhfan/p/9974805.html
https://www.cnblogs.com/zhhfan/p/9978099.html
导入包
import matplotlib.pyplot as plt
柱状图
最简柱状图
# 显示高度
def autolabel(rects):
for rect in rects:
height = rect.get_height()
plt.text(rect.get_x()+rect.get_width()/2.- 0.2, 1.03*height, '%s' % int(height))
name_list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
num_list = [33, 44, 53, 16, 11, 17, 17, 10]
autolabel(plt.bar(range(len(num_list)), num_list, color='rgb', tick_label=name_list))
plt.show()
堆叠柱状图
# 显示高度
def autolabel(rects1, rects2):
i = 0
for rect1 in rects1:
rect2 = rects2[i]
i += 1
height = rect1.get_height() + rect2.get_height()
plt.text(rect1.get_x()+rect1.get_width()/2. - 0.1, 1.03*height, '%s' % int(height))
name_list = ['A', 'B', 'C', 'D']
num_list = [10, 15, 16, 28]
num_list2 = [10, 12, 18, 26]
z1 = plt.bar(range(len(num_list)), num_list, label='1', fc='b')
z2 = plt.bar(range(len(num_list)), num_list2, bottom=num_list, label='2', tick_label=name_list, fc='g')
autolabel(z1, z2)
plt.legend()
plt.show()
并列柱状图
name_list = ['A', 'B', 'C', 'D']
num_list = [10, 15, 16, 28]
num_list2 = [10, 12, 18, 26]
x = list(range(len(num_list)))
total_width, n = 0.8, 2
width = total_width / n
plt.bar(x, num_list, width=width, label='1', fc='b')
for i in range(len(x)):
x[i] += width
plt.bar(x, num_list2, width=width, label='2', tick_label=name_list, fc='g')
plt.legend()
plt.show()
最简饼图
name_list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
num_list = [33, 44, 53, 6,11, 7, 7, 10, 3, 1]
# 保证圆形
plt.axes(aspect=1)
plt.pie(x=num_list, labels=name_list, autopct='%3.1f %%')
plt.show()
带切割的饼图
name_list = ['A', 'B', 'C', 'D']
num_list = [10, 3, 3, 47]
colors = ['green', 'yellow', 'blue', 'red']
# 圆形
plt.figure(1, figsize=(6, 6))
#决定分割部分,及其与其它部分之间的间距
expl = [0, 0, 0, 0.1]
plt.pie(x=num_list, explode=expl, labels=name_list, autopct='%3.1f %%', colors=colors, shadow=True)
plt.show()
https://www.cnblogs.com/zhhfan/p/9971757.html
https://www.jianshu.com/p/db220e016dae
https://blog.csdn.net/wuzlun/article/details/80053277
https://blog.csdn.net/ginynu/article/details/68944973
https://blog.csdn.net/fortware/article/details/51934814
https://www.jianshu.com/p/65395b00adbc
https://blog.csdn.net/jiangsujiangjiang/article/details/83650254
https://blog.csdn.net/moshiyaofei/article/details/88988873
https://blog.csdn.net/wuzlun/article/details/80319394