Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Matplotlib在图中填充空白_Python_Matplotlib - Fatal编程技术网

Python Matplotlib在图中填充空白

Python Matplotlib在图中填充空白,python,matplotlib,Python,Matplotlib,我在matplotlib中绘制了一个共享轴图,如下所示: 我试图在X轴的1月和12月附近填充一点空白,使其看起来更美观,但找不到任何方法。有人能提出一些建议吗 我的代码: fig, axes1 = plt.subplots(figsize=(12,8)) axes1.plot(misr_aod, label='MISR', color='blue', linestyle=':', linewidth=2, marker='+') axes1.plot(modis_aod, label='MO

我在matplotlib中绘制了一个共享轴图,如下所示:

我试图在X轴的1月和12月附近填充一点空白,使其看起来更美观,但找不到任何方法。有人能提出一些建议吗

我的代码:

fig, axes1 = plt.subplots(figsize=(12,8))

axes1.plot(misr_aod, label='MISR', color='blue', linestyle=':', linewidth=2, marker='+')
axes1.plot(modis_aod, label='MODIS', color='green', linestyle='-.', linewidth=2, marker='o')
axes1.plot(CESM_aod, label='CESM_AOD', color='red', linestyle='--', linewidth=2, marker='s')
axes1.set_ylim([0,0.8])
axes1.legend(loc=2)
axes1.set_xticks([-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
axes1.set_xticklabels(['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', ''])
axes1.grid(True)
axes1.set_xlabel('Months')
axes1.set_ylabel('AOD at 500 nm')


axes2 = axes1.twinx()

axes2.plot(APHRO_pcp, label='APHRO', color="magenta", linewidth=2, markerfacecolor="yellow", markeredgewidth=2, markeredgecolor="blue")
axes2.plot(IMD_pcp, label='IMD', color="purple", linewidth=2)
axes2.plot(TRMM_pcp, label='TRMM', color="green", linewidth=2)
axes2.plot(CESM_pcp, label='CESM_PRECT', color="red", linewidth=2)
axes2.set_ylim([0,10])
yticks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
axes2.set_yticks(yticks)
axes2.set_ylabel('PRECIPITATION (mm/day)')
axes2.legend()
plt.show()
可以使用在x轴上的数据前后自动填充一些空间

对于脚本,您只需要以下内容:

axes1.margins(x=0.05)

在两端添加5%的x范围。显然,您只需要调整
x
,以满足您的需要。

您可以显示您已经尝试过的代码吗?只需
ax。设置\u xlim
日期,日期略早于当年的1月,略晚于当年的12月。@wogsland我在问题中添加了代码