python 曲线图、柱状图、饼图


前言

Python 作图


一、曲线图

代码实例:

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(1,11)
y = x**2 + 5
plt.plot(x,y,color='b',linewidth = 3, linestyle='-')
plt.title("Matplotlib demo")       
plt.xlabel("x axis caption")
plt.ylabel("y axis caption")
plt.show()

python

二、柱状图

代码实例:

import matplotlib.pyplot as plt 
import matplotlib 
matplotlib.rcParams['font.sans-serif']=['SimHei'] 
matplotlib.rcParams['axes.unicode_minus']=False 
label_list=["12月","1月",'2月','3月','4月','5月']
list1=[58064,59531,61326,54704,53049,51155] 
list2=[47011,48099,47140,46476,45134,45705]
x=range(len(list1))
rects1=plt.bar(left=x,height=list1,width=0.4,color='blue',label="北京")
rects2=plt.bar(left=[i + 0.4 for i in x],height=list2,width=0.4,color='green',label="上海")
plt.ylim(40000,80000)
plt.ylabel("平均房价")
plt.xticks([index+0.2 for index in x],label_list)
plt.xlabel("月份")
plt.title("北京上海近六个月房产均价")
plt.legend() 
for rect in rects1:     
    height=rect.get_height() 
    plt.text(rect.get_x() + rect.get_width()/2,height+1,str(height),ha="center",va="bottom")
for rect in rects2:     
    height=rect.get_height()
    plt.text(rect.get_x() + rect.get_width()/2,height+1,str(height),ha="center",va="bottom") 
plt.show()

python


三、饼图

代码实例:

import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['axes.unicode_minus'] = False
label_list = ["优秀","良好","中等","及格","不及格"]
size = [10,19,19,23,29]
color = ["red","green","blue"]
explode = [0,0,0,0,0.05]
patches = plt.pie(size, explode=explode,colors=color, labels=label_list,
labeldistance=1.1,autopct="%1.1f%%",shadow=False,startangle=90,
pctdistance=0.6)
plt.axis("equal")
plt.legend()
plt.show()

python

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值