小编Luc*_*ian的帖子

如何使seaborn直方图的x刻度居中?

如果我们绘制非常简单的直方图:

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
Z = np.array([1, 2, 2, 2, 2, 2, 2, 3, 4, 5])
sns.histplot(Z, bins = 5)
plt.xticks([1, 2, 3, 4, 5])
plt.show()
Run Code Online (Sandbox Code Playgroud)

我们获得:

在此输入图像描述

我的问题是 - 是否有可能使这些刻度相对于 bin 居中?即我想1在第一个垃圾箱的中间打勾,2在第二个垃圾箱的中间打勾,即

你知道这是否可能吗?

正如评论中所建议的,我使用了discrete = True并且有效。但是,我不明白为什么它在创建子图时会刹车:

sns.set(rc={'figure.figsize':(10,15)})
X = np.array([1, 1, 1, 1, 1, 1, 2, 3, 4, 5]) 
Y = np.array([1, 2, 3, 4, 5, 5, 5, 5, 5, 5])
Z = np.array([1, 2, …
Run Code Online (Sandbox Code Playgroud)

python matplotlib seaborn

5
推荐指数
0
解决办法
2458
查看次数

直方图产生的值低于预期

让我们将 X 定义为:

在此处输入图片说明

以及与之相关的对象:

在此处输入图片说明

我想计算函数跟随的值,并将其绘制在具有 Y 特征值的同一图上。

在此处输入图片说明

我的工作到目前为止

# Define dimensions of X 
N=700;
T=900;
lambda=N/T;

# Randomize X
x=randn(N,T);
# Estimate standard deviation
s=std(x(:));
# Now we estimate y and it's eigenvalues
y=x*x'/T;
l=eig(y);
# Calculating lambda_plus and lambda_minus
lambda_plus=(s^2)*(1+sqrt(lambda))^2;
lambda_minus=(s^2)*(1-sqrt(lambda))^2;
x_lim = linspace(0.1, 3, 10^3)
# Taking into account indicator function
  if (x_lim <= lambda_plus && x_lim>= lambda_minus);
    smth=(1./(2*pi*lambda*x_lim*s^(2))).*sqrt((lambda_plus-x_lim).*(x_lim-lambda_minus));
  else 
    smth = 0
  endif
  # Normalize histogram
  [f, p] = hist(l, nbins = 20)
 hold on;
   bar(p, f …
Run Code Online (Sandbox Code Playgroud)

random matlab plot histogram octave

3
推荐指数
1
解决办法
42
查看次数

标签 统计

histogram ×1

matlab ×1

matplotlib ×1

octave ×1

plot ×1

python ×1

random ×1

seaborn ×1