0% found this document useful (0 votes)
5 views2 pages

Python Matplotlib Questions

The document outlines five tasks involving data visualization using Matplotlib in Python. Each task specifies the type of chart to create, the data to be used, and particular formatting or styling requirements. The tasks include a line chart for temperature comparison, a scatter plot for AQI and clinic visits, a horizontal bar chart for renewable energy capacity, a pie chart for energy mix proportions, and a histogram for daily rainfall distribution.

Uploaded by

k255524
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Python Matplotlib Questions

The document outlines five tasks involving data visualization using Matplotlib in Python. Each task specifies the type of chart to create, the data to be used, and particular formatting or styling requirements. The tasks include a line chart for temperature comparison, a scatter plot for AQI and clinic visits, a horizontal bar chart for renewable energy capacity, a pie chart for energy mix proportions, and a histogram for daily rainfall distribution.

Uploaded by

k255524
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Q1: Line Chart (Comparative Analysis) You are tracking the daily average

temperature for two different cities over a 5-day period.

●​ days = [Link](["Mon", "Tue", "Wed", "Thu", "Fri"])


●​ city_a_temp = [Link]([22, 24, 23, 26, 28])
●​ city_b_temp = [Link]([18, 19, 17, 20, 21])

Task: Write the Matplotlib code to plot both cities on the same line chart.

●​ Use a dashed line with circle markers for City A, and a solid line with square markers for
City B.
●​ Include a legend indicating which line belongs to which city.
●​ Add appropriate labels for the x-axis, y-axis, and a main title.

Q2: Scatter Plot (Multivariate Data) A climate researcher wants to visualize the
relationship between the Air Quality Index (AQI) and the number of reported respiratory
clinic visits, while also factoring in local humidity.

●​ aqi = [Link]([45, 120, 150, 60, 200, 300, 80, 110])


●​ clinic_visits = [Link]([10, 45, 60, 15, 80, 120, 25, 40])
●​ humidity = [Link]([30, 40, 60, 35, 70, 85, 45, 50])

Task: Write the code to generate a Scatter Plot mapping aqi to the x-axis and
clinic_visits to the y-axis.

●​ Use the humidity array to determine the color of the data points (using a colormap like
"viridis").
●​ Add a colorbar to the side of the plot to indicate the humidity scale.
●​ Set the transparency (alpha) of the points to 0.7.

Q3: Horizontal Bar Chart (Ranking Data) An environmental agency needs to present
the top 5 countries by renewable energy capacity (in Gigawatts).
●​ countries = [Link](["China", "USA", "Brazil", "India",
"Germany"])
●​ capacity_gw = [Link]([1100, 350, 180, 160, 140])

Task: Write the Matplotlib code to create a horizontal Bar Chart (barh).

●​ Color all bars "steelblue".


●​ Invert the y-axis so the country with the highest capacity appears at the top of the chart.
●​ Add the title "Top 5 Countries by Renewable Energy Capacity (GW)".

Q4: Pie Chart (Highlighting Proportions) You need to illustrate a city's power grid
energy mix to highlight its reliance on fossil fuels versus renewables.

●​ energy_sources = [Link](["Solar", "Wind", "Hydro", "Fossil


Fuels", "Nuclear"])
●​ percentages = [Link]([15, 10, 25, 40, 10])

Task: Write the Python code to draw a Pie Chart.

●​ Explode (pull out) the "Fossil Fuels" slice by 0.1 to emphasize it.
●​ Display the percentage values on the slices formatted to one decimal place (e.g.,
15.0%).
●​ Add a shadow effect to the pie chart for depth.

Q5: Histogram (Data Distribution) You have a large NumPy array representing the
daily rainfall (in mm) recorded over 365 days in a tropical region.

●​ Assume the data is loaded into a variable called daily_rainfall.

Task: Write the Matplotlib code to plot a Histogram showing the frequency distribution of the
rainfall data.

●​ Set the number of bins to 20.


●​ Outline the edges of the bins in "black" so they are easily distinguishable.
●​ Label the x-axis "Rainfall (mm)" and the y-axis "Number of Days".

You might also like