iron2man
iron2man

Reputation: 1827

Python - Plot axes descale in density plot

I have this initial plot.

enter image description here

Here is the code for this,

x = subhalos['SubhaloVelDisp']
y = (subhalos['SubhaloBHMass'] * 1e10 / 0.704) # in units of M_sol h^-1

logx = np.log(x)
logy = np.log(y)

plt.plot(logx, logy, '.')

plt.ylabel('$\log(M_{BH}$ / M$_{\odot}$)' )
plt.xlabel(' $\log(\sigma_{1D}$ / km s$^{-1}$)')
plt.title('$M_{BH}-\sigma$ relation')

Now, when plotting a density representation, my results are successful, giving me this, BUT my units on my axes have completely changed, yet it stills preserves the shape from the initial plot.

enter image description here

x = subhalos['SubhaloVelDisp']
y = subhalos['SubhaloBHMass'] * 1e10 / 0.704 # in units of M_sol h^-1


X = np.log10(x)
Y = np.log10(y)

x1 = X[np.isfinite(X)]
y1 = Y[np.isfinite(Y)]

x1.resize(y1.shape)

xy = np.vstack([x1,y1])
z = stats.gaussian_kde(xy)(xy)

idx = z.argsort()
x,y,z = x1[idx],y1[idx],z[idx]

fig, ax = plt.subplots()
ax.scatter(X,Y,c=z, s=25, edgecolor='')
plt.ylabel('$\log(M_{BH}$ / M$_{\odot}$)' )
plt.xlabel(' $\log(\sigma_{1D}$ / km s$^{-1}$)')
plt.title('$M_{BH}-\sigma$ relation')

The key things are that when passing the two arrays x and y in log form, I will get NaN values in the array. I then run both of them through the np.isfinite module and then i resize both of the arrays so that they are both the same shape.

What is going on here to have my values change on my axes?

Upvotes: 0

Views: 177

Answers (1)

h fsii
h fsii

Reputation: 41

I didn't understand the entire sequence but it looks like the difference in the axes is that you used

logx = np.log(x)
logy = np.log(y)

in the first example, and

X = np.log10(x)
Y = np.log10(y)

in the second.

Upvotes: 1

Related Questions