【发布时间】:2019-07-21 02:10:05
【问题描述】:
我正在尝试制作一些星数据的 CMD 图。
我正在使用提供给我的模块中的代码,它应该像复制和粘贴一样简单。然而,下面显示的错误被抛出。我已将 matplotlib 作为 plt.老实说,我实际上并没有理解第 6 行的任何内容,因此对发生的事情进行解释会有所帮助!
# 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```
【问题讨论】:
-
那个“重复”并没有回答这个问题。不过感谢您的参考!
-
和副本中的问题一样。你忘了导入 matplotlib。
标签: python matplotlib cmd