Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help understanding "matplotlib is not defined" error [duplicate]

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```
like image 228
Kibbles Avatar asked Apr 24 '26 02:04

Kibbles


1 Answers

It's using matplotlib AND plt.

You should

import matplotlib
import matplotlib.pyplot as plt
like image 115
politinsa Avatar answered Apr 25 '26 16:04

politinsa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!