error in creating subplots

Asked

Viewed 46 times

0

I am trying to create several Graphics using the following procedure:

fig_2, axes = plt.subplots(2,2, figsize=(20, 5))
axes[0].plot(abril.Date_Time, abril.CPUs_pct)
axes[1].plot(abril.Date_time, abril.Mem_pct)
axes[2].plot(abril.Date_time, abril.Swap_pct)

the error that gives is as follows:inserir a descrição da imagem aqui

I ask for a tip on how to solve this problem

Thank you

3 answers

0

The subplot Python takes as parameters the number of rows and columns to draw the grid with the graphs. For its code, fig_2, axes = plt.subplots(2,2, figsize=(20, 5)), the grid will have 4 graphics in a grid 2x2. To access the charts, the correct way is to say the row and column.

# axes[linha, coluna]
axes[0,0].plot(abril.Date_Time, abril.CPUs_pct)

This passage would place the graph .plot(abril.Date_Time, abril.CPUs_pct) on the line 0 and column 0.

0

Look I modified the code this way: fig_2, axes = plt.subplots(2, 2, figsize=(20, 5)) axes[0,0].plot(abril.Date_Time, abril.CPUs_pct) axes[0,1].plot(abril.Date_Time, abril.Mem_pct) axes[1,0].plot(abril.Date_Time, abril.Swap_pct) plt.show()

But there’s another mistake:

inserir a descrição da imagem aqui

-1

It is already solved, missing insert %matplotlib inline at the top.

Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.