Reputation: 61
I'm trying to solve a question on edx which I just can't seem to get right.
Despite the graph showing the system is saying "Did you call plt.show() twice?"
In the output it also shows this:
array([<matplotlib.axes._subplots.AxesSubplot object at 0x7f86702755c0>,
<matplotlib.axes._subplots.AxesSubplot object at 0x7f867020dbe0>,
<matplotlib.axes._subplots.AxesSubplot object at 0x7f867022c198>],
dtype=object)
Any help would be gratefully appreciated. Thanks
# Plot the data
sal_quantiles.plot()
# Set xticks
plt.xticks(
np.arange(len(sal_quantiles.index)),
sal_quantiles.index,
rotation='vertical')
# Show the plot
plt.show()
# Plot with subplots
sal_quantiles.plot(subplots=True)
Based on previous exercise.... Data source: https://raw.githubusercontent.com/fivethirtyeight/data/master/college-majors/recent-grads.csv
Now you're interested in plotting a few different quantiles of the average salary across major categories so that you can compare the different distributions of salary. In this exercise you'll prepare your data for matplotlib.
Instructions
The columns median, p25th, and p75th are currently encoded as strings. Convert these columns to numerical values. Then, divide the value of each column by 1000 to make the scale of the final plot easier to read.
Find the of each of the three columns for each major category. Save this as sal_quantiles
import pandas as pd
# Convert to numeric and divide by 1000
recent_grads['median'] = pd.to_numeric(recent_grads['median'])/ 1000
recent_grads['p25th'] = pd.to_numeric(recent_grads['p25th'])/ 1000
recent_grads['p75th'] = pd.to_numeric(recent_grads['p75th'])/ 1000
# Select averages by major category
columns = ['median', 'p25th', 'p75th']
sal_quantiles = recent_grads.groupby(['major_category'])['median', 'p25th', 'p75th'].mean()
print(sal_quantiles)
Upvotes: 2
Views: 1907
Reputation: 23
You need to display the image again, i.e. plt.show()
, after applying subplot=True
to pass the assessment.
Upvotes: 0