Set Ticks and Limits
Tâche
Swipe to start coding
Using the .set()
function, set the following parameters:
- limit values on the x-axis to
(0, 30000)
; - limit values on the y-axis to
(40, 80)
; - set ticks on the x-axis so that they will have a step of
5000
(for instance,0, 5000, 10000, 15000, ...
). You can use thenp.arange(start, end, step)
function there. It will generate numbers fromstart
toend
with the step ofstep
.
Solution
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Import the libraries
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# 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'])
# Set the plot limits and ticks
ax.set(xlim = (0, 30000), ylim = (40, 80), xticks = np.arange(0, 30000, 5000))
# Display the plot
plt.show()
Tout était clair ?
Merci pour vos commentaires !
Section 3. Chapitre 4
single
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Import the libraries
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# 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'])
# Set the plot limits and ticks
ax.set(___, ___, xticks = np.arange(___, ___, ___))
# Display the plot
plt.show()
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion