用python画满足幂律指数为-3的幂律分布的直方图和累积分布函数图
时间: 2023-05-19 17:05:10 浏览: 77
好的,以下是用Python画满足幂律指数为-3的幂律分布的直方图和累积分布函数图的代码:
```python
import numpy as np
import matplotlib.pyplot as plt
# 生成符合幂律分布的随机数
N = 10000
xmin = 1
alpha = 3
x = (np.random.power(alpha, N) * (1 - xmin) + xmin).astype(int)
# 画直方图
fig, ax = plt.subplots()
ax.hist(x, bins=50, density=True, alpha=0.7)
ax.set_xlabel('x')
ax.set_ylabel('Probability density')
ax.set_title('Power-law distribution with $\\alpha$ = {}'.format(alpha))
# 画累积分布函数图
fig, ax = plt.subplots()
counts, bins, patches = ax.hist(x, bins=50, density=True, cumulative=True, alpha=0.7)
ax.set_xlabel('x')
ax.set_ylabel('Cumulative probability')
ax.set_title('Cumulative distribution function of power-law distribution with $\\alpha$ = {}'.format(alpha))
plt.show()
```
希望这个代码能够帮到你!
阅读全文