Python绘图(demo10-demo11)

安装matplotlib

绘制条形图和饼图

from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号

绘制 条形

x = ['商品{}'.format(i) for i in 'ABCDEF']
print(x)
from  random import randint
y = [randint(1000, 2000) for i in range(6)]
print(y)
plt.bar(x, y)
plt.show()

饼图

labels = ['员工{}'.format(i) for i in range(1, 7)]
counts = [randint(2000, 15000) for i in range(6)]
print(counts)
# 距离中心点的距离
explode = [0.1, 0, 0, 0, 0, 0]
plt.pie(counts,
        explode=explode,
        labels = labels,
        shadow=True,
        autopct = '%1.1f')
plt.show()

折线图

from matplotlib import pyplot as plt
import numpy as pd
import numpy as np
x = [0, 1, 2, 3]
y = [0, 1, 2, 3]
plt.plot(x,y)
plt.show()

散点图

具有横轴和纵轴两个特征

# x = [0, 1, 2, 3]
# y = [0, 1, 2, 3]
# plt.scatter(x,y)
# plt.show()
x = np.random.normal(0,1,10000000)
y = np.random.normal(0,1,10000000)
# alpha透明度 o-1之间,越小越透明
plt.scatter(x,y,alpha=0.1)
plt.show()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容