简体   繁体   中英

Beginner question: Python scatter plot with normal distribution not plotting

I have an array of random integers for which I have calculated the mean and std , the standard deviation. Next I have an array of random numbers within the normal distribution of this (mean, std).

I want to plot now a scatter plot of the normal distribution array using matplotlib. Can you please help?

Code:

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)

The scatter plot needs x and y axis...but what should it be?

I think what you may want is a histogram of the normal distribution:

import matplotlib.pyplot as plt
%matplotlib inline

plt.hist(sample_norm_distrib)

在此处输入图片说明

The closest thing you can do to visualise your distribution of 1D output is doing scatter where your x & y are the same. this way you can see more accumulation of data in the high probability areas. For example:

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)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM