Im trying to make a CMD plot of some star data.
I am using code from a module provided to me that should be as simple as copying and pasting. Yet error shown below is thrown. I've imported matplotlib as plt. I don't actually understand any of line 6 to be honest, so an explanation of whats going on would be helpful!
# make a figure
fig = plt.figure(figsize=(20,10))
ax2 = fig.add_subplot(122)
# color-magnitude diagram (Hess diagram)
im2 = ax2.hexbin(df_cmd['f475w_vega']-df_cmd['f814w_vega'],df_cmd['f475w_vega'], \
gridsize=200,cmap=matplotlib.cm.viridis,norm=matplotlib.colors.LogNorm())
ax2.set_xlabel('F475W - F814W',fontsize=15)
ax2.set_ylabel('F475W',fontsize=15)
ax2.set_title('Color-magnitude (Hess) diagram',fontsize=20)
ax2.set_xlim(-1,5)
ax2.set_ylim(28.4,22)
#Error
NameError Traceback (most recent call last)
<ipython-input-36-be39ddc4e09d> in <module>()
4
5 # color-magnitude diagram (Hess diagram)
----> 6 im2 = ax2.hexbin(df_cmd['f475w_vega']-df_cmd['f814w_vega'],df_cmd['f475w_vega'], gridsize=200,cmap=matplotlib.cm.viridis,norm=matplotlib.colors.LogNorm())
7 ax2.set_xlabel('F475W - F814W',fontsize=15)
8 ax2.set_ylabel('F475W',fontsize=15)
NameError: name 'matplotlib' is not defined```
It's using matplotlib AND plt.
You should
import matplotlib
import matplotlib.pyplot as plt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With