Python Matplotlib 陆续整理

选择style

用法

#使用bmh
plt.style.use('bmh')

其余style参考:
Style sheets reference

设定plt参数:rcparameter

plt.rcParams.update({
    "legend.fancybox": True,
    "legend.frameon": True,
    # "text.usetex": True,
    "font.family": "serif",
    "font.serif": ["Times"],
    "lines.markersize": 2.5,
    "lines.linewidth":0.8,
    "font.size":6})

设定Times New Roman 字体,显示not found
原问题

sudo apt install msttcorefonts -qq
rm ~/.cache/matplotlib -rf

分辨率

最优方法

plt.savefig('filename.pdf')

手动设定分辨率

plt.savefig('filename.png', dpi=1000)

CDF曲线

PDF:probability density function 概率密度函数
CDF:cumulative distribution function 累积分布函数
pdf和cdf用于描述连续随机变量的概率分布

对于随机变量 X = [ x 1 , x 2 . . . x N ] X = [x_1,x_2...x_N] X=[x1,x2...xN],pdf表示 P ∣ ( x = x m ) P|(x=x_m) P(x=xm),即当x为 x m x_m xm时的概率
常见的pdf有正态分布和高斯分布等
对于pdf,概率曲线的面积(积分)等于1
CDF为 P ∣ ( x < = x m ) P|(x<=x_m) P(x<=xm),即当x小于等于xm时的概率,相当于在PDF图形基础上,x小于等于xm部分的面积(积分)

Python实现

stackoverflow原链接

# create some randomly ddistributed data:
data = np.random.randn(10000)

# sort the data:
data_sorted = np.sort(data)

# calculate the proportional values of samples
p = 1. * np.arange(len(data)) / (len(data) - 1)

# plot the sorted data:
fig = plt.figure()
ax1 = fig.add_subplot(121)
ax1.plot(p, data_sorted)
ax1.set_xlabel('$p$')
ax1.set_ylabel('$x$')

ax2 = fig.add_subplot(122)
ax2.plot(data_sorted, p)
ax2.set_xlabel('$x$')
ax2.set_ylabel('$p$')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值