这是我一段时间以来一直感兴趣的东西。我们显然可以创建一个 matplotlib 图并像这样旋转 xticklabels。
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(np.random.randn(1000).cumsum())
ax.set_title('Random Cumulative Sum')
ax.set_xlabel('Stages')
ax.set_xticks([0, 250, 500, 750, 1000])
ax.set_xticklabels(['one','two','three','four','five'],
rotation=30, fontsize='small')
Run Code Online (Sandbox Code Playgroud)
假设我宁愿使用字典来完成此操作。我可以制作一个(几乎)相同的情节使用
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(np.random.randn(1000).cumsum())
props = {'title': 'Random Cumulative Sum',
'xlabel': 'stages',
'xticks': [0,250,500,750,1000],
'xticklabels': ['one','two','three','four','five']}
ax.set(**props)
Run Code Online (Sandbox Code Playgroud)
我没有指定 xticklabels 需要在 props 字典中旋转。有没有办法将这些信息包含在字典中?
我正在尝试计算以下高斯的傅立叶变换:
# sample spacing
dx = 1.0 / 1000.0
# Points
x1 = -5
x2 = 5
x = np.arange(x1, x2, dx)
def light_intensity():
return 10*sp.stats.norm.pdf(x, 0, 1)+0.1*np.random.randn(x.size)
fig, ax = plt.subplots()
ax.plot(x,light_intensity())
Run Code Online (Sandbox Code Playgroud)
我在空间频域中创建了一个新数组(高斯的傅立叶变换是高斯,因此这些值应该相似)。我绘制并得到这个:
fig, ax = plt.subplots()
xf = np.arange(x1,x2,dx)
yf= np.fft.fftshift(light_intensity())
ax.plot(xf,np.abs(yf))
Run Code Online (Sandbox Code Playgroud)
为什么会分裂成两个峰?
python中计算逆卡方分布的对应函数是什么?例如,在 MATLAB 中,具有 n 个自由度的 95% 置信区间由下式给出
chi2inv(0.975,n)
Run Code Online (Sandbox Code Playgroud)