BaşlayınÜcretsiz Başlayın

Multiple lines on the same plot

You can also plot multiple datasets as different lines. To do so, you can use the plot() function multiple times. Let's plot the stocks of two companies over time.

matplotlib.pyplot is imported as plt and lists days, prices1, and prices2 are available in your workspace.

Bu egzersiz

Introduction to Python for Finance

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

Plot prices1 data with a red line, and prices2 data with a green line.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Plot two lines of varying colors 
plt.plot(days, ____, color='____')
plt.plot(days, ____, color='____')

# Add labels
plt.xlabel('Days')
plt.ylabel('Prices, $')
plt.title('Stock Prices Over Time')
plt.show()
Kodu Düzenle ve Çalıştır