Visualization and Analysis¶
Data visualizations are most useful when they effectively and accurately communicate answers to important questions about the data. A good plot helps the reader see a pattern, compare quantities, or notice an exception that would be hard to spot from a list of numbers.
Visualizations Can Be Deceptive
A good plot tells a story, but visualizations can be manipulated to tell a story that misrepresents the data, either by accident or on purpose to try to fit a desired narrative. Use visualizations to discover truth, not to form a narrative for a presupposed claim.
To visualize data effectively, it helps to first ask a specific question. For example, instead of asking “What does this student exam data look like?”, a better question might be, “Do students who spend more time studying tend to earn higher exam scores?” A good question suggests which variables to compare and what kind of plot might be useful.
After selecting a question, be purposeful about the takeaway. The goal is not to use every plotting command possible, but to help the reader understand the reasons for your conclusions. Axis labels, titles, marker sizes, colors, legends, and bin choices all matter because they direct the reader’s attention.
There is usually more than one reasonable way to show the same data.
A line plot shows how two variables relate with respect to an established ordering, such as showing how a variable changes over time.
A scatter plot shows the relationship between two variables.
A histogram shows the distribution of a single variable.
Choosing which type of plot to use, and which variables to compare, is central to the work of data visualization.
Problem 6
The file weather_data.npz contains 90 days of fictional weather data for one city, including the day recorded, the high temperature, the amount of precipitation (rain) in inches, and the average relative humidity as a percentage. Upload the data to Google Colab and load it into Python with the following code.
weather = np.load("weather_data.npz")
day = weather["day"]
temperature = weather["high_temperature"]
precipitation = weather["precipitation"]
humidity = weather["humidity"]
Use one or more plots to answer the following questions:
How often does it rain? Were there any dry spells over the 90-day period?
How do temperature, humidity, and precipitation trend over the 90-day period?
Is precipitation more strongly associated with temperature or humidity? How?
Clearly label each plot and write an analysis of the data based on your visualizations.
Submitting this lab
For this lab only, turn in a PDF file generated by printing from Google Colab (File > Print) after executing the entire notebook.
Ensure all plots are visible in the resulting file.
More Useful Commands¶
The following commands are frequently useful.
plt.xticks()andplt.yticks()set the tick locations and labels on their respective axes.plt.grid()adds a background grid.plt.savefig("figure.pdf", dpi=200)exports the current figure to a local file. This works with PDF, PNG, and other image formats. Callplt.savefig()beforeplt.show()to save a figure correctly.