Python可视化学习笔记二

一、定义图表类型-柱状图、线形图和堆积柱状图

# -*- coding: UTF-8 -*-

from matplotlib.pyplot import *
import matplotlib.pyplot as plt

def for_example():
    #plot储存数据集,多组数据展现多条线
    '''
    plot([1,2,3,2,3,2,2,1])
    plot([4,3,2,1],[1,2,3,4])
    '''
    x=[1,2,3,4]
    y=[5,4,3,2]
    #创建一个新的图表
    figure()
    #创建一个图表中的子图
    subplot(231)#括号里面是2行3列第一个图,中间也可以是(2,3,1)
    plot(x,y)

    subplot(232)
    bar(x,y)

    subplot(233)
    barh(x,y)

    subplot(234)
    bar(x,y)

    y1=[7,8,5,3]
    bar(x,y1,bottom=y,color='r')

    subplot(235)
    boxplot(x)

    subplot(236)
    scatter(x,y)

    plt.show()

if __name__ == '__main__':
    for_example()

这里写图片描述

散点图

def san_dian_picture():
    x = np.random.rand(1000)#生成随机值
    y1= np.random.randn(len(x))
    y2= 1.2+np.exp(x)#对矩阵a中每个元素取指数函数,ex

    ax1=plt.subplot(121)
    plt.scatter(x,y1,color='indigo',alpha=0.3,edgecolors='white',label='no correl')
    plt.xlabel('no correlation')
    plt.grid(True)
    plt.legend()

    ax2=plt.subplot(122,sharey=ax1,sharex=ax1)
    plt.scatter(x,y2,color='green',alpha=0.3,edgecolors='grey',label='correl')
    plt.xlabel('strong correlation')
    plt.grid(True)
    plt.legend()

    plt.show()

这里写图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值