Matplotlib 简单绘直方图、饼图、极坐标图、气泡图

本文介绍了如何使用Matplotlib库在Python中绘制直方图、饼图、极坐标图和气泡图。直方图示例展示了hist函数的用法,包括参数设置和返回值解释。同时,文章提及了饼图、不常用的极坐标图以及通过面积大小展示第三维数据的气泡图,强调了在Python数据可视化中的学习价值。
摘要由CSDN通过智能技术生成

1 直方图:效果图和代码如下:

import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

# example data
mu = 100
sigma = 15
x = mu + sigma*np.random.randn(1000)

#直方图的条数
num_bins = 50
n, bins, patches = plt.hist(x, num_bins, normed=1, facecolor = "b", alpha=0.5)
#添加一个拟合曲线,返回概率密度函数
y = mlab.normpdf(bins, mu, sigma)
plt.plot(bins,y,"r--")
#fontproperties显示中文simHei Lishu STSong Kaiti FangSong YouYuan 
plt.xlabel("横轴",fontproperties = "simHei",fontsize = 14)
plt.ylabel("纵轴",fontproperties = "simHei",fontsize = 14)
plt.title("simple histogram")
#text(x,y,str)指定图像位置输入文字;latex语法$$添加公式
plt.text(100,0.033,"$\mu=100$,$\sigma=15$")
#调整图像的间距,防止y轴数值与label重合
plt.subp
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值