I have been trying to plot a histogram fitted with a gaussian, the mean along with 1 sigma standard deviation errors. Using ff.create_distplot does not allow us to choose the range for the y axis we require, it automatically normalizes it. I have tried using the matplotlib version of things and tried making it work on plotly but without any avail.
My code is given below.
Any help will be appreciated. Thank You.
从图像中您可以看到高斯已标准化。如何将其缩放到 y 轴?
GX= pd.read_csv(r'X.....X.
csv')
df = pd.DataFrame(GX, columns = ['ra','dec','rest','b_rest','B_rest','pmra','pmra_error','pmdec','pmdec_error','PM'])
ra = df['ra'].tolist()
dec = df['dec'].tolist()
rest = df['rest'].tolist()
b_rest = df['b_rest'].tolist()
B_rest = df['B_rest'].tolist()
pmra = df['pmra'].tolist()
pmra_E = df['pmra_error'].tolist()
pmdec = df['pmdec'].tolist()
pmdec_E = df['pmdec_error'].tolist()
PM = df['PM'].tolist()
PM1 = []
c = 0
for i in range(len(PM)):
if (PM[i]<100 and pmra[i]>-4.5 and pmra[i]<1.5 and pmdec[i]>1 and pmdec[i]<3):
PM1.append(PM[i])
c+=1
group_labels = ['Proper Motion']
color = ['#636EFA', '#EF553B', '#00CC96', '#AB63FA', '#FFA15A', '#19D3F3', '#FF6692', '#B6E880', '#FF97FF', '#FECB52']
fig = go.Figure()
fig.add_trace(
go.Histogram(
x = PM1
)
)
mean = np.mean(PM1)
variance = np.var(PM1)
sigma = np.sqrt(PM1)
fig.add_trace(
go.Scatter(
name = 'Gaussian',
mode = 'lines',
x = PM1,
y = mlab.normpdf(PM1, mean, sigma)
)
)
#Line Plot for mean
mean = np.mean(PM1)
stdev_pluss = mean + np.std(PM1)
stdev_minus = mean - np.std(PM1)
median = np.median(PM1)
fig.add_trace(
go.Scatter(
name = 'Mean',
x=[2.769491040712437]*1000,
y = np.linspace(0,105,num = 1000),
mode="lines",
marker=dict(
size=2,
line=dict(
color = 'rgb(128,177,211)',
width=1
)
)
)
)
#Line Plot for Median
fig.add_trace(
go.Scatter(
name = 'Median',
x=[2.800431666]*1000,
y = np.linspace(0,105,num = 1000),
mode="lines",
marker=dict(
size=2,
line=dict(
color = 'rgb(128,177,211)',
width=1
)
)
)
)
#Plotting Standard Deviation Lines
fig.add_trace(
go.Scatter(
name = 'Stdev-',
x=[(stdev_minus)]*1000,
y = np.linspace(0,105,num = 1000),
mode="lines",
marker=dict(
size=2,
line=dict(
color = 'rgb(128,177,211)',
width=1
)
)
)
)
fig.add_trace(
go.Scatter(
name = 'Stdev+',
x=[(stdev_pluss)]*1000,
y = np.linspace(0,105,num = 1000),
mode="lines",
marker=dict(
size=2,
line=dict(
color = 'rgb(128,177,211)',
width=1
)
)
)
)
fig.update_layout(
title = 'Proper Motion Histogram + Gaussian distribution ',
xaxis = dict(
title='Proper Motion'
),
yaxis = dict(
title='Count'
),
template = 'plotly_dark',
showlegend = True
)
fig.show()
print('Mean :{}\nMedian: {}\nStandard Deviation: {}'.format(mean,median,stdev))