Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Gráficos de Barras Apiladas | Creating Commonly Used Plots
Ultimate Visualization with Python

Gráficos de Barras ApiladasGráficos de Barras Apiladas

Los gráficos de barras apiladas son útiles cuando queremos comparar varias categorías (dos o más) para cada valor del eje x. Por ejemplo, en lugar de fijarnos únicamente en el PIB de los distintos países, podemos querer ver la cantidad de contribución de cada sector económico al PIB de un país concreto (los datos no son reales):

Code Description
plt.bar(countries, primary_sector)

Plotting the lower bars for primary_sector (blue bars).

plt.bar(countries, secondary_sector, bottom=primary_sector)

Plotting the middle bars for secondary_sector (orange bars) on top of the lower bars for primary_sector.

plt.bar(countries, tertiary_sector, bottom=primary_sector + secondary_sector)

Plotting the upper bars for tertiary_sector (green bars) on top of the middle bars.

Similarly to line plots and scatter plots, we called the bar() function three times to create three bars for each value on the x-axis (country names in our example). In every call countries are specified as x-axis values in order to create stacked bars. Pay extra attention to the bottom parameter.

Note

bottom parameter specifies the y coordinate(s) of the bottom side(s) of the bars. Here is the documentation.

Tarea

  1. Utilice la función correcta para crear gráficos de barras.
  2. Trace las barras inferiores para yes_answers.
    1. Trace las barras de "sin_respuestas" encima de las barras de "sí_responde" especificando la palabra clave correcta.

¿Todo estuvo claro?

Sección 2. Capítulo 5
toggle bottom row
course content

Contenido del Curso

Ultimate Visualization with Python

Gráficos de Barras ApiladasGráficos de Barras Apiladas

Los gráficos de barras apiladas son útiles cuando queremos comparar varias categorías (dos o más) para cada valor del eje x. Por ejemplo, en lugar de fijarnos únicamente en el PIB de los distintos países, podemos querer ver la cantidad de contribución de cada sector económico al PIB de un país concreto (los datos no son reales):

Code Description
plt.bar(countries, primary_sector)

Plotting the lower bars for primary_sector (blue bars).

plt.bar(countries, secondary_sector, bottom=primary_sector)

Plotting the middle bars for secondary_sector (orange bars) on top of the lower bars for primary_sector.

plt.bar(countries, tertiary_sector, bottom=primary_sector + secondary_sector)

Plotting the upper bars for tertiary_sector (green bars) on top of the middle bars.

Similarly to line plots and scatter plots, we called the bar() function three times to create three bars for each value on the x-axis (country names in our example). In every call countries are specified as x-axis values in order to create stacked bars. Pay extra attention to the bottom parameter.

Note

bottom parameter specifies the y coordinate(s) of the bottom side(s) of the bars. Here is the documentation.

Tarea

  1. Utilice la función correcta para crear gráficos de barras.
  2. Trace las barras inferiores para yes_answers.
    1. Trace las barras de "sin_respuestas" encima de las barras de "sí_responde" especificando la palabra clave correcta.

¿Todo estuvo claro?

Sección 2. Capítulo 5
toggle bottom row
some-alt