码迷,mamicode.com
首页 > 其他好文 > 详细

matplot 代码实例2

时间:2015-04-25 10:41:59      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

要画出如上图(注意原点有边距),怎么办呢?

简单而优雅,请看代码:

#!/usr/bin/env python
# coding=utf-8

import matplotlib.pyplot as plt


def loadData():
    x = [1,2,3,4,5]
    y = [1,4,8,9,7]
    labelsx = [Apple,Banana,Orange,Pear,Cherry]
    return x,y,labelsx

def drawGraph():
    x,y,labels_x = loadData()
    plt.plot(x,y,ro)
    plt.xticks(x,labels_x,rotation=vertical)

    plt.xlabel("Fruits")
    plt.ylabel("Price")
    plt.title(" The Price of the Fruits")

    plt.margins(0.3)
    plt.subplots_adjust(bottom=0.15)
    plt.show()

if __name__=="__main__":
    drawGraph()

 

参考:http://matplotlib.org/examples/index.html

matplot 代码实例2

标签:

原文地址:http://www.cnblogs.com/jkmiao/p/4455452.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!