python可视化——常见的图表

1.常规的画图-折线图`

import numpy as np
import matplotlib.pyplot as plt
np.random.seed(1000)
y=np.random.standard_normal(20)
# print(y)
plt.plot(y.cumsum()) #cumsum可以获取数据的总和

结果如下:
在这里插入图片描述
2.双折线图

import numpy as np
import matplotlib.pyplot as plt
np.random.seed(2000)
y=np.random.standard_normal((200,2)).cumsum(axis=0)
plt.figure(figsize=(7,4))
plt.plot(y,lw=1.5)
plt.plot(y,'g-')
plt.grid(True)
plt.legend(loc=2)
plt.axis('tight')
plt.xlabel('index')
plt.ylabel('value')
plt.title('a simple plot')

结果如下:
在这里插入图片描述
3.双折线图,同时现实双坐标轴

fig,ax1=plt.subplots() #使用第一个(左边)的坐标轴画第一组数据
plt.plot(y[:,0],'b',lw=1.5,label='1st')
plt.plot(y[:,0],'r')
plt.grid(True)
plt.legend(loc=8)
plt.axis('tight')
plt.xlabel('index')
plt.ylabel('value 1st')
ax2=ax1.twinx() #用第二个坐标轴(右边)画第二组数据
plt.plot(y[:,1],'g',lw=1.5,label='2nd')
plt.plot(y[:,1],'r')
plt.legend(loc=0)
plt.ylabel('value 2nd')

结果如下
在这里插入图片描述
4.柱状图

import numpy as np
y=np.random.standard_normal((20,2)).cumsum(axis=0)
print(y)
print(y[:,0])
print(y[:,1])

plt.bar(np.arange(len(y)),y[:,0],width=0.5,color="g",label='1st')
plt.grid(True)
plt.legend(loc=0)

结果如下
在这里插入图片描述
5.散点图

y=np.random.standard_normal((1000,2))
plt.figure(figsize=(7,5))
plt.plot(y[:,0],y[:,1],'ro')
plt.grid(True)
plt.xlabel('1st')
plt.ylabel('2nd')
plt.title('scatter plot')

结果如下
在这里插入图片描述
6.散点图加上第三维

c=np.random.randint(0,10,len(y)) #随机数据生成第三个数据集
plt.figure(figsize=(7,5))
plt.scatter(y[:,0],y[:,1],c=c,marker='o')
plt.colorbar()
plt.grid(True)
plt.xlabel('1st')
plt.ylabel('2nd')
plt.title('scatter plot')

结果如下
在这里插入图片描述
7.直方图

plt.figure(figsize=(7,4))
plt.hist(y,label=['1st','2nd'],bins=25)
plt.grid(True)
plt.legend(loc=0)
plt.xlabel('value')
plt.ylabel('frequency')
plt.title('histogram')

结果如下
在这里插入图片描述
8.箱型图

fig,ax=plt.subplots(figsize=(7,4))
plt.boxplot(y)
plt.grid(True)
plt.setp(ax,xticklabels=['1st','2nd'])
plt.xlabel('data set')
plt.ylabel('value')
plt.title('Boxplot')

结果如下
在这里插入图片描述
本期分享就到这里,边学习边分享。

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

马尔可夫宽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值