zoukankan      html  css  js  c++  java
  • 用python画xy散点图

    import matplotlib.pyplot as plt
    plt.plot([1,2,3],[4,5,6],'ro')
    plt.show()#这个智障的编辑器

    这样的话,就可以画一个散点图,图中的点分别是(1,4)、(2,5)、(3,6)。

    是不是挺难看的,我们来调整一下x,y 的上下界,再画一遍。

    import matplotlib.pyplot as plt 
    plt.xlim(xmax=7,xmin=0)
    plt.ylim(ymax=7,ymin=0)
    plt.plot([1,2,3],[4,5,6],'ro')
    plt.show()

    好了,好像没那么难看了。加个标题吧。就叫我是散点图吧。还是先查个字典,看看散点图怎么说吧,用中文说不定会出啥错。

    import matplotlib.pyplot as plt
    plt.title("I'm a scatter diagram.") plt.xlim(xmax
    =7,xmin=0) plt.ylim(ymax=7,ymin=0) plt.plot([1,2,3],[4,5,6],'ro') plt.show()

    还不错!索性给x,y轴命个名吧。

    import matplotlib.pyplot as plt
    plt.title("I'm a scatter diagram.") 
    plt.xlim(xmax=7,xmin=0)
    plt.ylim(ymax=7,ymin=0)
    plt.xlabel("x")
    plt.ylabel("y") plt.plot([
    1,2,3],[4,5,6],'ro') plt.show()

    这时候加点标注,最适合不过了。

    import matplotlib.pyplot as plt
    plt.title("I'm a scatter diagram.") 
    plt.xlim(xmax=7,xmin=0)
    plt.ylim(ymax=7,ymin=0)
    plt.annotate("(3,6)", xy = (3, 6), xytext = (4, 5), arrowprops = dict(facecolor = 'black', shrink = 0.1))
    plt.xlabel("x")
    plt.ylabel("y")
    plt.plot([1,2,3],[4,5,6],'ro')
    plt.show()

    现在还干点啥呢?多画几个图试试。

    import matplotlib.pyplot as plt
    
    plt.subplot(221)
    plt.xlim(xmax=7,xmin=0)
    plt.ylim(ymax=7,ymin=0)
    plt.xlabel("x")
    plt.ylabel("y")
    plt.plot([1,2,3],[4,5,6],'ro')
    
    plt.subplot(222)
    plt.xlim(xmax=7,xmin=0)
    plt.ylim(ymax=7,ymin=0)
    plt.xlabel("x")
    plt.ylabel("y")
    plt.plot([1,2,3],[4,5,6],'ro')
    
    
    plt.subplot(223)
    plt.xlim(xmax=7,xmin=0)
    plt.ylim(ymax=7,ymin=0)
    plt.xlabel("x")
    plt.ylabel("y")
    plt.plot([1,2,3],[4,5,6],'ro')
    
    plt.show()

    至于221、222、223什么意思,自己研究研究,就应该知道了。


    就先这样吧。

  • 相关阅读:
    OpenWRT Mac 虚拟机PD 分享 for 软路由
    How to write u disk from img in mac os x
    linux find file > 100 M
    gojs for data flow
    正则表达式
    grep
    搜索引擎Query Rewrite
    Kafka replication
    cassandra写数据CommitLog
    Solr DIH JDBC 源码解析
  • 原文地址:https://www.cnblogs.com/super-zhang-828/p/4792206.html
Copyright © 2011-2022 走看看