Misinterpretation

Report a typo

Suppose you want to visualize the data containing the letter grade distributions among students with a stem plot. Here's the code:

import matplotlib.pyplot as plt

grades = {"AA": 5, "AB": 8, "BB": 7, "BC": 7, "CC": 9, "CD": 4, "DD": 3, "FF": 7}
letter_grades = list(grades.keys())
number_of_grades = list(grades.values())
plt.figure(figsize=(7, 7))
plt.vlines(x=letter_grades, ymin=0, ymax=number_of_grades, color="blue")
plt.plot(letter_grades, number_of_grades, "o")
plt.title("Number of grades for each letter grade", fontsize=16)
plt.xlabel("Letter grades", fontsize=15)
plt.ylabel("Number of grades", fontsize=15)
plt.show()

When you run the code, you get a vertical plot:

A vertical plot

How to change this code to get a horizontal plot:

Horizontal plot

Select a single answer from the options below (the answer should be the option number):

1) Line 7 should be changed to

plt.hlines()

2) Line 7 and 8 should be changed to

plt.hlines(y=letter_grades, xmin=0, xmax=number_of_grades, color='blue')
plt.plot(number_of_grades, letter_grades, 'o')

3) Insert the following line after line 8:

plt.orientation('horizontal')

4) Line 7 should be changed to

plt.hlines(y=letter_grades, xmin=0, xmax=number_of_grades, color='blue')

Enter a short text
___

Create a free account to access the full topic