Вертикальные линии не появляются там, где они должны быть в pyplot - pandas - PullRequest
0 голосов
/ 26 февраля 2020

Я хочу построить график и наложить желтые вертикальные линии, где выравнивание столбца имеет значение -1, но мне не удается.

Для воспроизводимого примера некоторые данные:

'{"Alignment":{"1569888000000":1.0,"1569974400000":1.0,"1570060800000":1.0,"1570147200000":1.0,"1570406400000":1.0,"1570492800000":1.0,"1570579200000":1.0,"1570665600000":1.0,"1570752000000":1.0,"1571011200000":1.0,"1571097600000":1.0,"1571184000000":1.0,"1571270400000":1.0,"1571356800000":1.0,"1571616000000":1.0,"1571702400000":1.0,"1571788800000":1.0,"1571875200000":1.0,"1571961600000":1.0,"1572220800000":1.0,"1572307200000":1.0,"1572393600000":1.0,"1572480000000":1.0,"1572566400000":1.0,"1572825600000":1.0,"1572912000000":1.0,"1572998400000":1.0,"1573084800000":1.0,"1573171200000":1.0,"1573430400000":1.0,"1573516800000":-1.0},"Pct_chng_actual":{"1569888000000":1.1,"1569974400000":1.5,"1570060800000":1.9,"1570147200000":3.3,"1570406400000":4.6,"1570492800000":3.3,"1570579200000":1.1,"1570665600000":4.7,"1570752000000":3.1,"1571011200000":2.9,"1571097600000":5.3,"1571184000000":5.0,"1571270400000":6.5,"1571356800000":3.2,"1571616000000":2.6,"1571702400000":0.3,"1571788800000":1.6,"1571875200000":-2.8,"1571961600000":-2.5,"1572220800000":-1.4,"1572307200000":-1.3,"1572393600000":-0.7,"1572480000000":-1.2,"1572566400000":1.3,"1572825600000":2.6,"1572912000000":5.5,"1572998400000":6.8,"1573084800000":4.7,"1573171200000":3.2,"1573430400000":2.0,"1573516800000":1.5},"Pct_chng_pred_lightGBM":{"1569888000000":1.1,"1569974400000":2.3,"1570060800000":3.2,"1570147200000":4.5,"1570406400000":6.0,"1570492800000":3.5,"1570579200000":2.6,"1570665600000":1.8,"1570752000000":3.2,"1571011200000":3.4,"1571097600000":3.4,"1571184000000":3.0,"1571270400000":3.1,"1571356800000":1.7,"1571616000000":0.4,"1571702400000":0.3,"1571788800000":0.1,"1571875200000":-1.6,"1571961600000":-1.0,"1572220800000":-1.2,"1572307200000":-2.0,"1572393600000":-0.5,"1572480000000":-2.8,"1572566400000":1.7,"1572825600000":2.6,"1572912000000":4.1,"1572998400000":3.6,"1573084800000":6.8,"1573171200000":4.4,"1573430400000":0.9,"1573516800000":-2.6}}'

Мой код:

from matplotlib.dates import DateFormatter
fig, ax = plt.subplots()
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
ax.xaxis_date()
ax.bar(x = df_test.index, height = df_test['Pct_chng_actual'], color = 'red', label = 'Ground Truth Percent Change of Price', alpha = 0.5)
ax.bar(x = df_test.index, height = df_test['Pct_chng_pred_lightGBM'], color = 'blue', label = 'Predicted Percent Change of Price',
       alpha = 0.5)
[ax.axvline(x, c='y', **{'alpha' : 0.5, 'lw' : 10}) for x in df_dev[df_dev['Alignment'] == -1].index]
plt.legend()
plt.title(f'Ground Truth and Predicted Percent Change of the Price over a Horizon of 10 BDays in the Test Set \n \
- Test Set', fontsize = 18)

что я получу:

enter image description here

Как мне исправить свой код?

...