• matplotlib_200730系列---3、移动坐标轴


    matplotlib_200730系列---3、移动坐标轴

    一、总结

    一句话总结:

    1、get current axis:ax=plt.gca()
    2、去掉右轴和上轴,比如去掉右轴:ax.spines['right'].set_color('none')
    3、将bottom轴设置为x轴,将left轴设置为y轴,比如前者:ax.xaxis.set_ticks_position('bottom')
    4、将x轴设置在y=0的位置:ax.spines['bottom'].set_position(('data',0))
    import matplotlib.pyplot as plt 
    import numpy as np 
    x=np.linspace(-3,3,50)
    y1=2*x+1
    y2=x**2
    
    plt.figure()
    plt.plot(x,y2)
    plt.plot(x, y1, color='red', linewidth=1, linestyle='--')
    
    plt.xlabel("x")
    plt.ylabel("y")
    
    # gca='get current axis'
    ax=plt.gca()
    # 将右和上的轴去掉
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    # 将bottom轴设置为x轴
    ax.xaxis.set_ticks_position('bottom') 
    # 将left轴设置为y轴
    ax.yaxis.set_ticks_position('left')
    # 将x轴设置在y=0的位置
    ax.spines['bottom'].set_position(('data',0))
    # 将y轴设置为x=0的位置
    ax.spines['left'].set_position(('data',0))
    
    plt.show()

    二、移动坐标轴

    博客对应课程的视频位置:

    import matplotlib.pyplot as plt 
    import numpy as np 
    x=np.linspace(-3,3,50)
    y1=2*x+1
    y2=x**2
    
    plt.figure()
    plt.plot(x,y2)
    plt.plot(x, y1, color='red', linewidth=1, linestyle='--')
    
    plt.xlabel("x")
    plt.ylabel("y")
    
    # gca='get current axis'
    ax=plt.gca()
    # 将右和上的轴去掉
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    # 将bottom轴设置为x轴
    ax.xaxis.set_ticks_position('bottom') 
    # 将left轴设置为y轴
    ax.yaxis.set_ticks_position('left')
    # 将x轴设置在y=0的位置
    ax.spines['bottom'].set_position(('data',0))
    # 将y轴设置为x=0的位置
    ax.spines['left'].set_position(('data',0))
    
    plt.show()

     
    我的旨在学过的东西不再忘记(主要使用艾宾浩斯遗忘曲线算法及其它智能学习复习算法)的偏公益性质的完全免费的编程视频学习网站: fanrenyi.com;有各种前端、后端、算法、大数据、人工智能等课程。
    博主25岁,前端后端算法大数据人工智能都有兴趣。
    大家有啥都可以加博主联系方式(qq404006308,微信fan404006308)互相交流。工作、生活、心境,可以互相启迪。
    聊技术,交朋友,修心境,qq404006308,微信fan404006308
    26岁,真心找女朋友,非诚勿扰,微信fan404006308,qq404006308
    人工智能群:939687837

    作者相关推荐

  • 相关阅读:
    Ruby:Hash 排序
    Rails bug: ROR + A server is already running. Check …/tmp/pids/server.pid. Exiting
    MySQL 删除数据的最好的方式
    FATAL ERROR: The persistent cache of section information does not match the current configu...
    http和https的区别
    SAP BusinessObject < Aggregate Navigation >
    BO Server Session Setting
    BusinessObject Port 配置
    重复提交
    FCKeditor
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/13401648.html
Copyright © 2020-2023  润新知