我正在尝试使用以下代码生成子图
fig, axes = plt.subplot(3, 2)
axes[0, 0].pcolor(dataset_one[0], dataset_one[1], dataset_two[2], cmap='jet', vmin=-100, vmax=10000)
axes[0, 0].set_title('Raw Scattering Data along (4, K, 0)')
axes[1, 0].pcolor(dataset_two[0], dataset_two[1], dataset_two[2], cmap='jet', vmin=-100, vmax=10000)
axes[1, 0].set_title('Raw Scattering Data along (H, 4, 0)')
axes[2, 0].pcolor(dataset_three[0], dataset_three[1], dataset_three[2], cmap='jet', vmin=-100, vmax=10000)
axes[2, 0].set_title('Raw Scattering Data along (4, 0, L)')
axes[0, 1].pcolor(dataset_one_subtracted[0], dataset_one_subtracted[1], dataset_one_subtracted[2], cmap='jet', vmin=-100, vmax=10000)
axes[1, 1].pcolor(dataset_two_subtracted[0], dataset_two_subtracted[1], dataset_two_subtracted[2], cmap='jet', vmin=-100, vmax=10000)
axes[2, 1].pcolor(dataset_three_subtracted[0], dataset_three_subtracted[1], dataset_three_subtracted[2], cmap='jet', vmin=-100, vmax=10000)
fig.xlabel('Momentum Transfer (r.l.u)')
fig.ylabel('Energy Transfer (meV)')
fig.title('Neutron Scattering Data for Lead Magnesium Niobate (PMN)')
但出现以下错误:
Traceback (most recent call last):
File "subplots_E_vs_Q.py", line 257, in <module>
fig, axes = plt.subplot(3, 2)
File "/home/s1406403/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 1072, in subplot
a = fig.add_subplot(*args, **kwargs)
File "/home/s1406403/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py", line 1239, in add_subplot
a = subplot_class_factory(projection_class)(self, *args, **kwargs)
File "/home/s1406403/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_subplots.py", line 72, in __init__
raise ValueError('Illegal argument(s) to subplot: %s' % (args,))
ValueError: Illegal argument(s) to subplot: (3, 2)
在浏览了文档和其他教程之后,我仍然不确定代码(尤其是参数)是什么问题。
最佳答案
我相信应该是plt.subplots(3,2)
加上一个s
关于python - Python分割,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58064387/