Create a Complete Line Chart
Good job! I think you can now build an informative chart yourself with real data.
Let's just recap the necessary steps:
- Load the
matplotlib.pyplotlibrary. Preferably withpltalias; - Create
FigureandAxesobjects using.subplots()function (preferablyfig, ax); - Initialize each line with
ax.plot()functions with necessary data and customization parameters (label,color,marker,linestyle); - Set axis labels using
ax.set_xlabel()andax.set_ylabel()functions; - Display the plot title, legend using
plt.title()andplt.legend()functions (legendrequireslabelparameter within.plot()functions to be set); - Display the plot using
plt.show()function.
Swipe to start coding
You are given the us_cities_weather dataframe containing the weather data for the US cities (average temperature per month from 1961 - 1990 in Fahrenheit). You need to display the monthly average temperature for three cities: San Francisco, Denver, and Miami. Follow the next steps:
-
Create
FigureandAxesobjects assigned tofig,axvariables respectively. -
Save data for each city in a separate variable (
dvfor Denver,sffor San Francisco, andmmfor Miami). -
Set the parameters for three lines (each corresponding to the respective city):
-
Red (
'r') dotted ('dotted') line with square ('s') points for San Francisco; -
Blue (
'b') dashed ('dashed') line with triangle ('^') points for Denver; -
Orange (
'darkorange') dashdotted ('dashdot') line with circle ('o') points for Miami.
-
-
Set the labels for the plot:
-
'Month'on the x-axis; -
'Average Temperature (Fahrenheit)'on the y-axis.
-
-
Add plot title
'Average monthly temperature for the US cities'. -
Add a legend and display the plot.
Løsning
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Oppsummer dette kapittelet
Explain code
Explain why doesn't solve task
Awesome!
Completion rate improved to 2.94
Create a Complete Line Chart
Sveip for å vise menyen
Good job! I think you can now build an informative chart yourself with real data.
Let's just recap the necessary steps:
- Load the
matplotlib.pyplotlibrary. Preferably withpltalias; - Create
FigureandAxesobjects using.subplots()function (preferablyfig, ax); - Initialize each line with
ax.plot()functions with necessary data and customization parameters (label,color,marker,linestyle); - Set axis labels using
ax.set_xlabel()andax.set_ylabel()functions; - Display the plot title, legend using
plt.title()andplt.legend()functions (legendrequireslabelparameter within.plot()functions to be set); - Display the plot using
plt.show()function.
Swipe to start coding
You are given the us_cities_weather dataframe containing the weather data for the US cities (average temperature per month from 1961 - 1990 in Fahrenheit). You need to display the monthly average temperature for three cities: San Francisco, Denver, and Miami. Follow the next steps:
-
Create
FigureandAxesobjects assigned tofig,axvariables respectively. -
Save data for each city in a separate variable (
dvfor Denver,sffor San Francisco, andmmfor Miami). -
Set the parameters for three lines (each corresponding to the respective city):
-
Red (
'r') dotted ('dotted') line with square ('s') points for San Francisco; -
Blue (
'b') dashed ('dashed') line with triangle ('^') points for Denver; -
Orange (
'darkorange') dashdotted ('dashdot') line with circle ('o') points for Miami.
-
-
Set the labels for the plot:
-
'Month'on the x-axis; -
'Average Temperature (Fahrenheit)'on the y-axis.
-
-
Add plot title
'Average monthly temperature for the US cities'. -
Add a legend and display the plot.
Løsning
Takk for tilbakemeldingene dine!
single