Plot P/E ratios
Let's take a closer look at the P/E ratios using a scatter plot for each company in these two sectors.
The arrays it_pe
and cs_pe
from the previous exercise are available in your workspace. Also, each company name has been assigned a numeric ID contained in the arrays it_id
and cs_id
.
This exercise is part of the course
Introduction to Python for Finance
Exercise instructions
- Draw a scatter plot of
it_pe
ratios with red markers and'IT'
label. - On the same plot, add the
cs_pe
ratios with green markers and'CS'
label. - Add a legend to this plot.
- Display the plot.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
import matplotlib.pyplot as plt
# Make a scatterplot
plt.____(it_id, it_pe, ____, ____)
____(cs_id, cs_pe, ____, ____)
# Add legend
____
# Add labels
plt.xlabel('Company ID')
plt.ylabel('P/E Ratio')
____