[Numpy-discussion] numpy histogram data

2021-06-06 Thread Keith Sloan
Okay I have some data which I have created a scatter plot

 

I have also created a histogram of red Galaxy counts for redshift with

RedEllipticalMasses.keep_columns(['uminusr','Z_1'])
RedEllipticalMasses.sort(['Z_1','uminusr'])
counts, bins = np.histogram(RedEllipticalMasses['Z_1'],bins=80)
fig, ax = plt.subplots(1, 1, figsize=(12,8)) # make the figure with the size
10 x 8 inches
fig.suptitle("2 - Histogram Count of Red Galaxies versus Redshift")
plt.hist(bins[:-1], bins, weights=counts)
plt.show()

 

Is there a way to created the histogram data for a stacked histogram formed
from different ranges of redness 'uminusr'?

Also is there an easy way of extracting the point information for the
midpoints of each histogram column?

Thanks



--
Sent from: http://numpy-discussion.10968.n7.nabble.com/
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] numpy histogram data

2021-06-07 Thread Keith Sloan
Thanks

Not sure where I get centers & edges from

# Plot of Histogram of Stacked Counts of Red elliptical Galaxies versus
Red Shift
REMrange1 =
RedEllipticalMasses[RedEllipticalMasses[RedEllipticalMasses['uminusr']>1.8]['uminusr']
<2.0]
print(len(REMrange1))
counts1, bins1 = np.histogram(REMrange1['Z_1'],bins=bins)
REMrange2a = RedEllipticalMasses[RedEllipticalMasses['uminusr']>2.0]
REMrange2 = REMrange2a[REMrange2a['uminusr'] <2.2]
counts2, bins2 = np.histogram(REMrange2['Z_1'],bins=bins)
REMrange3a = RedEllipticalMasses[RedEllipticalMasses['uminusr']>2.2]
REMrange3 = REMrange3a[REMrange3a['uminusr'] <2.4]
counts3, bins3 = np.histogram(REMrange3['Z_1'],bins=bins)
REMrange4a = RedEllipticalMasses[RedEllipticalMasses['uminusr']>2.4]
REMrange4 = REMrange4a[REMrange4a['uminusr'] <2.6]
counts4, bins4 = np.histogram(REMrange4['Z_1'],bins=bins)
REMrange5a = RedEllipticalMasses[RedEllipticalMasses['uminusr']>2.6]
REMrange5 = REMrange5a[REMrange5a['uminusr'] <2.8]
counts5, bins5 = np.histogram(REMrange5['Z_1'],bins=bins)
counts = [counts1, counts2, counts3, counts4, counts5] 
centers = [centers for _ in counts] 
fig, ax = plt.subplots(1, 1, figsize=(12,8)) # make the figure with the size
10 x 8 inches
fig.suptitle("2 - Histogram Counts of Red Galaxies versus Redshift")
ax.set_xlabel('Redshift Z')
ax.set_ylabel('Counts of Galaxies')
plt.hist(centers, bins=bins, weights=counts, stacked=True)
plt.show()

Barfs on
NameError Traceback (most recent call last)
 in 
 53 counts5, bins5 = np.histogram(REMrange5['Z_1'],bins=bins)
 54 counts = [counts1, counts2, counts3, counts4, counts5]
---> 55 centers = [centers for _ in counts]
 56 fig, ax = plt.subplots(1, 1, figsize=(12,8)) # make the figure with
the size 10 x 8 inches
 57 fig.suptitle("2 - Histogram Counts of Red Galaxies versus Redshift")



--
Sent from: http://numpy-discussion.10968.n7.nabble.com/
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] numpy histogram data

2021-06-07 Thread Keith Sloan
Thanks

Okay trying to understand the data being returned.
I have 

counts, bins = np.histogram(RedEllipticalMasses['Z_1'],bins=80)

If I print lengths I get
RedEllipticalMasses is 2514
bins = 81
and counts is 5
( It is 5 Arrays each of length 80)

Okay I can get centers with
centers = 0.5 * (bins[1:] + bins[:-1]

As you advised
But unclear how I would get their heights and why counts has 5 arrays ?



--
Sent from: http://numpy-discussion.10968.n7.nabble.com/
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] numpy histogram data

2021-06-08 Thread Keith Sloan
There really is not a lot of other code.

RedEllipticalMasses is an Astropy Table read in from a fits file
from astropy.table import Table, join
import numpy as np
RedEllipticalMasses =
Table.read('../../GAMA_Data/REMassEClassEmeasure.fits')
RedEllipticalMasses['Z_1'] is a single column name 'Z_1'

If. I print its type I get




--
Sent from: http://numpy-discussion.10968.n7.nabble.com/
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion