LoslegenKostenlos loslegen

Importing matplotlib and pyplot

Pyplot is a collection of functions in the popular visualization package Matplotlib. Its functions manipulate elements of a figure, such as creating a figure, creating a plotting area, plotting lines, adding plot labels, etc. Let's use the plot() function from pyplot to create a dashed line graph showing the growth of a company's stock. Remember, you can change the color of the line by adding the argument color and the linestyle by adding the argument linestyle.

Two lists, days (representing the days since the company became public), and prices (representing the price of the stock corresponding to that day) are available in your workspace.

Diese Übung ist Teil des Kurses

Introduction to Python for Finance

Kurs anzeigen

Anleitung zur Übung

  • Selectively import the pyplot module of matplotlib as plt.
  • Plot days on the x-axis and prices on the y-axis as a red colored dashed line.
  • Display the plot with the show() function.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Import matplotlib.pyplot with the alias plt
import matplotlib.pyplot as ____

# Plot the price of stock over time
plt.plot(____, ____, color="____", linestyle="____")

# Display the plot
plt.____()
Code bearbeiten und ausführen