python3.8自带matlop和numpy吗_python3.8自带matlop和numpy吗_python之matloplib可视化

importmatplotlib.pyplot as pltimportnumpy as np

x= np.linspace(-10, 20, 50, True)

y= 2 * x + 5

#一、画散点图

plt.scatter(x,y,s=40,c='Orange',edgecolors='k',marker='s',alpha=0.5)#s:大小;c:内部颜色;edgecolors:边框颜色;marker:点的形状;alpha:透明度

plt.show()

matplot画板颜色请点击这里;点的形状请点击这里#二、画折线图与线段

plt.figure()

plt.plot(x, y, label='line1')

plt.plot(x, y+ 4, c='r', lw=2, ls=':', label='line2')#c:颜色;lw:线宽;ls:线段类型,有“:”“--”“-”等;lebel:画图图例;

plt.plot([-10, 0], [-10, 0], ls='--', label='line3') #两点连线

plt.legend()

plt.show()#三、画柱状图#1、单一柱状图

plt.figure()

bar_x= np.arange(5)

bar_y= np.arange(5)

rects= plt.bar(bar_x, height=bar_y, width=0.8,orientation='vertical')#给每个柱添加数据标识

for rect inrects:

plt.text(rect.get_x()+ rect.get_width() / 2, rect.get_height(), rect.get_height(), ha='center', va='bottom')

plt.show()#2、横向柱状图#method 1 :

plt.figure()

plt.barh(bar_y,bar_x,height=0.8,left=0) #left柱状图左边的起始位置,0表示从x=0开始

plt.show()#method 2 :

plt.figure()

plt.bar(x=0,bottom=bar_x, width=bar_y, height=0.5,orientation='horizontal') #bottom:柱状图底部起始位置为y=bar_x,orientation设置柱状图方向

plt.show()#3、并列图

plt.figure()

plt.bar(bar_x, height=bar_y, width=0.2,orientation='vertica

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值