Python - форматирование отметок на графике - PullRequest
0 голосов
/ 11 июля 2020

Я работаю с некоторым кодом, который отображает 3 разных временных ряда на одном графике с подзаголовками, где на оси времени отображается каждый 12-й временной ряд, используя следующий код . Смотрите прикрепленный скриншот. enter image description here Later in my code, I am running impulse response functions and plotting those with almost identical code, and am having issues with it plotting the time axis correctly.

This is the code for those plots.

T = 36
time3 = np.linspace(0,T,T+1)

#Plot Impulse Response Functions
zeros = np.zeros(T+1)
fig, axes = plt.subplots(nrows=3, ncols=1, dpi=120, figsize=(10,6))
for i, ax in enumerate(axes.flatten()):
    #plot the IRFs
    data = IRF_data_EPU[i]
    ax.plot(time3, data, color='blue', linewidth=1)
    #plot the IRF standard error bands
    lower = IRF_lower_EPU[i]
    upper = IRF_upper_EPU[i]
    ax.plot(lower, '--', color='black', linewidth=1)
    ax.plot(upper, '--', color='black', linewidth=1)
    #include a line for the x axis at zero
    ax.plot(zeros, color='black',linewidth=1)
    # Decorations
    ax.set_title(df_sub.columns[i])
    ax.set_xticks(ax.get_xticks()[::3])
    ax.yaxis.set_ticks_position('none')
    ax.spines["top"].set_alpha(0)
    ax.tick_params(labelsize=6)

plt.tight_layout();

However, running this code creates issues with the x-axis. Instead of displaying every third value from 0 to 36, the x axis is plotting values from -5 to 40 and then using seemingly random values for the ticks.

This is the graph before adding the code for the ticks on the x-axis enter image description here

And this is the graph with the ticks set. The only part of the code that was changed was adding the line for ax.set_xticks(ax.get_xticks()[::3]) введите описание изображения здесь

Я попытался прокомментировать построение чего-либо, кроме импульсных характеристик, но это не исправляет, поэтому что-то не так с построением данных по временной последовательности.

Любая помощь в исправлении будет приветствоваться.

...