如何将顶部x轴日期标签与底部x轴对齐?

2024-04-19 13:13:05 发布

您现在位置:Python中文网/ 问答频道 /正文

Current result

我从一个.csv文件中绘制了一组数据,使用“twiny”在顶部x轴上显示(YYYY-mm-dd)格式的日期,在底部x轴上显示浮动时间值。然而,所得到的曲线本应完全相同,但似乎只在一个中心x轴点重合,该点在左右两侧都有周期性的偏移趋势。我一直在广泛地寻找解决这个问题的办法,但现有的解决办法似乎都不起作用。数据文件是使用pandas创建的。你知道吗

我附上了下面的绘图程序。请告诉我怎样才能更好地描述这个问题。你知道吗

fig, ax = plt.subplots(1, 1, figsize=(13,
8),sharex=True,sharey=True)
font = {'family': 'serif', 'serif': ['Times New Roman'],
'color':
'black', 'weight': 'normal', 'size': 17.0}
ax.errorbar(tmid_met_ul, flux_ul, xerr=terr_met_ul,
yerr=flux_err_ul, color='black', fmt='.g', ecolor='gray',
elinewidth=1.5, capsize=3, markersize=13.5, label=None)

ax.set_xlabel('Time in MET (s)', fontsize=20, **tnrfont)


plt.plot(x1_data, y1_data, '_', color='blue', alpha=0.6)
plt.quiver(x1_data, y1_data, 0, -1, color='blue', alpha=0.6,
width=0.00225, headwidth=4.75, headlength=5)
plt.xticks(fontname = "Times New Roman")
plt.yticks(fontname = "Times New Roman")
ax.set_ylabel(r'Flux (ph cm$\mathbf{^{-2}}$
s$\mathbf{^{-1}}$)', fontsize=20, **tnrfont)
ax.xaxis.set_tick_params(labelsize=17)
ax.yaxis.set_tick_params(labelsize=17)

ax2 = ax.twiny()

ax2.scatter(new_df['tmid_date_STR'].tolist(),new_df['flux'],
color = 'red')

ax2.tick_params(rotation=90)
plt.savefig("lightcurve_weekly.pdf", dpi=250, facecolor='w',
edgecolor='w',orientation='landscape', papertype=None,
format=None,transparent=False, bbox_inches='tight',
pad_inches=0.05,frameon=None)

Tags: nonenewdatapltparamsaxulcolor