Visualizing Economic Data with matplotlib
Data visualization is a cornerstone of economic analysis, allowing you to interpret and communicate complex trends in a clear and persuasive way. In economics, visual tools help you quickly spot patterns, compare indicators across countries, and make informed decisions based on empirical evidence. Whether you are tracking GDP growth, unemployment rates, or inflation, effective visualizations transform raw data into actionable insights.
12345678910111213141516171819202122232425import matplotlib.pyplot as plt import pandas as pd # Sample GDP data (in billions USD) data = { "Year": [2015, 2016, 2017, 2018, 2019, 2020], "USA": [18224, 18707, 19485, 20612, 21433, 21138], "Germany": [3371, 3479, 3650, 3948, 3861, 3806], "Japan": [4384, 4939, 4850, 4971, 5082, 5065] } df = pd.DataFrame(data) plt.figure(figsize=(8, 5)) plt.plot(df["Year"], df["USA"], label="USA", marker="o") plt.plot(df["Year"], df["Germany"], label="Germany", marker="o") plt.plot(df["Year"], df["Japan"], label="Japan", marker="o") plt.xlabel("Year") plt.ylabel("GDP (Billions USD)") plt.title("GDP Over Time (2015-2020)") plt.legend() plt.grid(True) plt.tight_layout() plt.show()
This line plot shows GDP over time for the USA, Germany, and Japan. The horizontal axis (x-axis) represents the years, while the vertical axis (y-axis) shows GDP in billions of USD. Each country is represented by a line with distinct markers, and the legend identifies which line corresponds to which country. Labels on the axes ensure you know what each dimension represents, while the title provides context for the plot. By observing the slopes and relative positions of the lines, you can quickly compare economic growth and spot trends, such as steady increases or periods of decline.
12345678910111213import matplotlib.pyplot as plt # Sample unemployment data for 2020 countries = ["USA", "Germany", "Japan"] unemployment_rates = [8.1, 4.2, 2.8] plt.figure(figsize=(6, 4)) plt.bar(countries, unemployment_rates, color=["royalblue", "darkorange", "seagreen"]) plt.xlabel("Country") plt.ylabel("Unemployment Rate (%)") plt.title("Unemployment Rates in 2020") plt.tight_layout() plt.show()
1. What type of plot is best for showing changes in GDP over time?
2. Fill in the blank: To add a legend to a matplotlib plot, you would use _ _ _.
3. Why is it important to label axes in economic data visualizations?
Kiitos palautteestasi!
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Mahtavaa!
Completion arvosana parantunut arvoon 4.76
Visualizing Economic Data with matplotlib
Pyyhkäise näyttääksesi valikon
Data visualization is a cornerstone of economic analysis, allowing you to interpret and communicate complex trends in a clear and persuasive way. In economics, visual tools help you quickly spot patterns, compare indicators across countries, and make informed decisions based on empirical evidence. Whether you are tracking GDP growth, unemployment rates, or inflation, effective visualizations transform raw data into actionable insights.
12345678910111213141516171819202122232425import matplotlib.pyplot as plt import pandas as pd # Sample GDP data (in billions USD) data = { "Year": [2015, 2016, 2017, 2018, 2019, 2020], "USA": [18224, 18707, 19485, 20612, 21433, 21138], "Germany": [3371, 3479, 3650, 3948, 3861, 3806], "Japan": [4384, 4939, 4850, 4971, 5082, 5065] } df = pd.DataFrame(data) plt.figure(figsize=(8, 5)) plt.plot(df["Year"], df["USA"], label="USA", marker="o") plt.plot(df["Year"], df["Germany"], label="Germany", marker="o") plt.plot(df["Year"], df["Japan"], label="Japan", marker="o") plt.xlabel("Year") plt.ylabel("GDP (Billions USD)") plt.title("GDP Over Time (2015-2020)") plt.legend() plt.grid(True) plt.tight_layout() plt.show()
This line plot shows GDP over time for the USA, Germany, and Japan. The horizontal axis (x-axis) represents the years, while the vertical axis (y-axis) shows GDP in billions of USD. Each country is represented by a line with distinct markers, and the legend identifies which line corresponds to which country. Labels on the axes ensure you know what each dimension represents, while the title provides context for the plot. By observing the slopes and relative positions of the lines, you can quickly compare economic growth and spot trends, such as steady increases or periods of decline.
12345678910111213import matplotlib.pyplot as plt # Sample unemployment data for 2020 countries = ["USA", "Germany", "Japan"] unemployment_rates = [8.1, 4.2, 2.8] plt.figure(figsize=(6, 4)) plt.bar(countries, unemployment_rates, color=["royalblue", "darkorange", "seagreen"]) plt.xlabel("Country") plt.ylabel("Unemployment Rate (%)") plt.title("Unemployment Rates in 2020") plt.tight_layout() plt.show()
1. What type of plot is best for showing changes in GDP over time?
2. Fill in the blank: To add a legend to a matplotlib plot, you would use _ _ _.
3. Why is it important to label axes in economic data visualizations?
Kiitos palautteestasi!