本篇文章给大家谈谈基于python的图表生成系统,以及基于python的图表绘图工具,希望对各位有所帮助,不要忘了收藏本站喔。
40张python图表
1. 条形图
# 库
import numpy as np
import matplotlib.pyplot as plt
# 创建数据集
height = [3, 12, 5, 18, 45]
bars = ('A', 'B', 'C', 'D', 'E')
x_pos = np.arange(len(bars))
# 创建条形图
plt.bar(x_pos, height)
# 在x轴上创建名称
plt.xticks(x_pos, bars)
# 显示图形
plt.show()
#水平条形图
import matplotlib.pyplot as plt
import numpy as np
height = [3, 12, 5, 18, 45]
bars = ('A', 'B', 'C', 'D', 'E')
y_pos = np.arange(len(bars))
#height后面加上代码color=(0.2, 0.4, 0.6, 0.6)可以改变颜色
plt.barh(y_pos, height)
plt.yticks(y_pos, bars)
plt.show()
# 堆垛条形图
# 库
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
import pandas as pd
rc('font', weight='bold')
bars1 = [12, 28, 1, 8, 22]
bars2 = [28, 7, 16, 4, 10]
bars3 = [25, 3, 23, 25, 17]
bars = np.add(bars1, bars2).tolist()
r = [0,1,2,3,4]
names = ['A','B','C','D','E']
barWidth = 1
plt.bar(r, bars1, color='#7f6d5f', edgecolor='white', width=barWidth)
plt.bar(r, bars2, bottom=bars1, color='#557f2d', edgecolor='white', width=barWidth)
plt.bar(r, bars3, bottom=bars, color=