-1

I have the following code:

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)

This makes the following plot:

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')

enter image description here

As you can see there is no legend

Slartibartfast
  • 1,058
  • 4
  • 26
  • 60

1 Answers1

1

Instead of ax.plot(), use ax.fill_between():

plt.fill_between(your_x_list, your_y_list, label=your_label)
Red
  • 26,798
  • 7
  • 36
  • 58