Графики области построения с форматированием оси x - PullRequest
0 голосов
/ 10 июля 2020

У меня есть следующий код:

population = pd.DataFrame(data = population)
fig, ax = plt.subplots(figsize = (10, 5))
population.columns = ['pop']
# ax.area(population['pop'], kind ='area')
# ax = population.plot.area()


ax.fill_between: ax.fill_between(population.index, population['pop'], alpha=0.3, label='Population')
ax.xaxis.set_major_locator(md.YearLocator())
ax.xaxis.set_major_formatter(md.DateFormatter('%Y'))
plt.setp(ax.xaxis.get_majorticklabels(), rotation = 90)
ax.set_xlim([population.index[0], population.index[-1]])
ax.fill_between(population['pop'],0)

Это дает следующий график:

enter image description here

How can i plot an area plot. If i do this:

ax.plot(population['pop'], kind ='area')

I get the following error:

AttributeError: 'Line2D' object has no property 'kind'

If i do this:

ax = population.plot.area()

enter image description here

It leaves the entire formatting on the x-axis. How can i plot area? Edit:

I get the following plot enter image description here

For legend:

I added the following line:

ax.fill_between: ax.fill_between(population.index, population['pop'], alpha=0.3, label='Population')

введите описание изображения здесь

Как видите, легенды нет

1 Ответ

1 голос
/ 10 июля 2020

Вместо ax.plot() используйте ax.fill_between():

plt.fill_between(your_x_list, your_y_list, label=your_label)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...