Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Create a Simple Scatter Plot | Scatter Plots
Visualization in Python with matplotlib

book
Create a Simple Scatter Plot

Tarea

Swipe to start coding

The 'gapminder' data is loaded in the dataframe data. Your tasks are:

  1. Initialize scatter plot with the 'gdp per capita' column values on the x-axis, and 'life exp' column values on the y-axis.
  2. Display the plot.

Solución

# Import the libraries
import pandas as pd
import matplotlib.pyplot as plt

# Load the data
data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/ed80401e-2684-4bc4-a077-99d13a386ac7/gapminder2017.csv', index_col = 0)

# Create Figure and Axes objects
fig, ax = plt.subplots()

# Initialize the scatter plot
ax.scatter(data['gdp per capita'], data['life exp'])

# Display the plot
plt.show()

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 2
# Import the libraries
import pandas as pd
import matplotlib.pyplot as plt

# Load the data
data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/ed80401e-2684-4bc4-a077-99d13a386ac7/gapminder2017.csv', index_col = 0)

# Create Figure and Axes objects
fig, ax = plt.subplots()

# Initialize the scatter plot
___.___(data['___'], data['___'])

# Display the plot
___.___()
toggle bottom row
some-alt