В pandas, как я могу получить гистограмму временного ряда с хорошей осью x (как тот, который я получаю с простым графиком) - PullRequest
0 голосов
/ 13 апреля 2020

С этим фрагментом:

import pandas as pd
import matplotlib.pyplot as plt

json = '{"timestamp":{"0":"2020-03-04","1":"2020-03-05","2":"2020-03-06","3":"2020-03-07","4":"2020-03-08"},"a":{"0":1.0,"1":16.0,"2":0.0,"3":null,"4":3.0},"b":{"0":0.0,"1":2.0,"2":0.0,"3":null,"4":5.0}}'
df = pd.read_json(json,convert_dates=True)
df.set_index('timestamp',inplace=True)
print(df)

fig, ax1 = plt.subplots(1)
df.plot.bar(ax=ax1)
ax1.set_title('fig1')
ax1.figure.savefig('fig1.png',bbox_inches='tight')

fig, ax2 = plt.subplots(1)
df.plot(ax=ax2)
ax2.set_title('fig2')
ax2.figure.savefig('fig2.png',bbox_inches='tight')

Я получаю следующие цифры.

enter image description here

enter image description here

Я бы хотел получить гистограмму, подобную fig1, но с осью х, похожей на ось в fig2.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...