Python 点参数对matplotlib中的曲线图有什么作用

Python 点参数对matplotlib中的曲线图有什么作用,python,python-3.x,matplotlib,Python,Python 3.x,Matplotlib,当matplotlib的violinplot中的points参数发生变化时会发生什么情况?什么时候这样做有用 点小提琴图的参数定义如下 点:标量,默认值=100 定义评估每个高斯核密度估计值的点数 当我改变图表时,我看到它几乎没有什么变化。为什么会这样呢?根据[官方文件](第二个重点矿山)() 点:标量,默认值=100 定义用于评估每个高斯核密度估计值的点数。 因此,如下例(改编自)所示,当选择非常少量的点时,会突出显示点数的效果。当然,结果也取决于样本量。尝试选择较小的样本大小,如size=5

matplotlib
violinplot
中的points参数发生变化时会发生什么情况?什么时候这样做有用

小提琴图的参数定义如下

点:标量,默认值=100

定义评估每个高斯核密度估计值的点数


当我改变图表时,我看到它几乎没有什么变化。为什么会这样呢?

根据[官方文件](第二个重点矿山)()

:标量,默认值=100 定义用于评估每个高斯核密度估计值的点数。

因此,如下例(改编自)所示,当选择非常少量的点时,会突出显示点数的效果。当然,结果也取决于样本量。尝试选择较小的样本大小,如
size=5
,然后运行下面相同的代码。随着点的增加,密度估计的平滑度自然会提高。在一些要接受收敛测试的截止点数量上,您将看不到明显的影响

import numpy as np
import matplotlib.pyplot as plt

# Fixing random state for reproducibility
np.random.seed(19680801)


fs = 10  # fontsize
pos = [1, 2, 4, 5, 7, 8]
data = [np.random.normal(0, std, size=100) for std in pos]

fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(10, 3))

axes[0].violinplot(data, pos, points=2, widths=1,
                      showmeans=True, showextrema=True, showmedians=True)
axes[0].set_title('Custom violinplot 1', fontsize=fs)

axes[1].violinplot(data, pos, points=5, widths=1,
                      showmeans=True, showextrema=True, showmedians=True,
                      bw_method='silverman')
axes[1].set_title('Custom violinplot 2', fontsize=fs)

axes[2].violinplot(data, pos, points=100, widths=1,
                      showmeans=True, showextrema=True, showmedians=True,
                      bw_method='silverman')
axes[2].set_title('Custom violinplot 2', fontsize=fs)

for ax in axes.flat:
    ax.set_yticklabels([])

plt.tight_layout()

<强> P.S.:进一步强调这一点,只考虑一个位置和三个例子:5, 10个和50个点,如“认真考虑< < /P>”建议的那样。

pos = [1]
data = [np.random.normal(0, std, size=100) for std in pos]

这有点难理解,所以也许像这样的东西会让第一眼看到更容易。@ImportanceOfBeingErnest:谢谢你的提示。用类似的东西更新了答案
pos = [1]
data = [np.random.normal(0, std, size=100) for std in pos]