【问题标题】:Beginner question: Python scatter plot with normal distribution not plotting初学者问题:不绘制正态分布的 Python 散点图
【发布时间】:2018-10-28 07:14:33
【问题描述】:

我有一个随机整数数组,我计算了meanstd 的标准偏差。接下来我在这个(平均值,标准)的正态分布内有一个随机数数组。

我现在想使用 matplotlib 绘制正态分布数组的散点图。你能帮忙吗?

代码:

random_array_a = np.random.randint(2,15,size=75)  #random array from [2,15) 
mean = np.mean(random_array_a)     
std = np.std(random_array_a)    
sample_norm_distrib = np.random.normal(mean,std,75)

散点图需要x轴和y轴...但是应该是什么?

【问题讨论】:

  • 很难知道,你要求什么,当你不知道,它是什么。也许你的任务是关于Normal Probability Plot

标签: python numpy matplotlib data-science scatter-plot


【解决方案1】:

我认为您可能想要的是正态分布的直方图:

import matplotlib.pyplot as plt
%matplotlib inline

plt.hist(sample_norm_distrib)

【讨论】:

  • 感谢您的评论。我必须为我的作业发布散点图。
  • 哦,我认为直方图比散点图更有意义,问题是你想要散点图上的什么,散点图的代码是 plt.scatter(x,y)
【解决方案2】:

您可以做的最接近一维输出分布的可视化操作是在 x 和 y 相同的地方进行散布。这样你可以在高概率区域看到更多的数据积累。例如:

import numpy as np
import matplotlib.pyplot as plt

mean = 0    
std = 1 
sample_norm_distrib = np.random.normal(mean,std,7500)

plt.figure()
plt.scatter(sample_norm_distrib,sample_norm_distrib)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 2011-09-11
    • 2021-07-01
    相关资源
    最近更新 更多