Customizing axis labels and adding titles
Customizing the axis labels requires using the set_xlabel and set_ylabel methods of the Axes object. Adding a title uses the set_title method.
In this exercise, you will customize the content of the axis labels and add a title to a plot.
As before, the data is already provided in pandas DataFrame objects loaded into memory: seattle_weather and austin_weather. These each have a "MONTH" column and a "MLY-PRCP-NORMAL" column. These data are plotted against each other in the first two lines of the sample code provided.
In addition, a Figure object named fig and an Axes object named ax have already been created for you.
Latihan ini adalah bagian dari kursus
Introduction to Data Visualization with Matplotlib
Petunjuk latihan
- Use the
set_xlabelmethod to add the label:"Time (months)". - Use the
set_ylabelmethod to add the label:"Precipitation (inches)". - Use the
set_titlemethod to add the title:"Weather patterns in Austin and Seattle".
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-PRCP-NORMAL"])
ax.plot(austin_weather["MONTH"], austin_weather["MLY-PRCP-NORMAL"])
# Customize the x-axis label
____
# Customize the y-axis label
____
# Add the title
____
# Display the figure
plt.show()