Visualizing Apple Stock Trends with Pyplot: Identifying Highs and Lows

Plot Apple's highest and lowest prices using pyplot's scatterplot method.

Learn how to visualize Apple's historical stock prices using Python's pyplot library, including methods to pinpoint and plot significant highs and lows. Gain practical experience in identifying and marking critical data points on stock price charts.

Key Insights

  • The tutorial demonstrates plotting Apple's historical stock prices by using Python's pyplot with the BMH style, visualizing closing prices over time.
  • It explains how to identify and retrieve significant data points, such as the lowest stock price, by using pandas functions like min() and indexing techniques.
  • The article introduces an additional challenge to readers, suggesting the use of pyplot's scatterplot method to highlight both the highest and lowest points on the plotted graph.

Note: These materials offer prospective students a preview of how our classes are structured. Students enrolled in this course will receive access to the full set of materials, including video lectures, project-based assignments, and instructor feedback.

Let's plot some data. First, I am going to want the low, so I'm going to add that here as well. Get rid of the prints, we don't really need those.

Let's add, find the lowest price in the data frame. That'll be lowest apple price equals, and it's going to be very similar, really the reverse. I want the low dot min.

Give me the lowest of the lows, and then let's find the row with that price. Low date is apple prices, and it will be apple prices. Yeah, apple prices at the low column equals our lowest apple price.

And finally, let's actually get the date from that. That'll be low date is actually low date at dot index and index zero. Let's run that block again.

And now, first, now that we're graphing it, let's just see, I don't have quite everything here, but if I run this, it's going to make a big old pyplot figure using the BMH style. And we say go plot the dates as X's against the closing prices as the Y. And then pyplot, show that graph. And here it is.

Python for Data Science Bootcamp: Live & Hands-on, In NYC or Online, Learn From Experts, Free Retake, Small Class Sizes,  1-on-1 Bonus Training. Named a Top Bootcamp by Forbes, Fortune, & Time Out. Noble Desktop. Learn More.

Here's apple's low, low prices in the early aughts, and then jumping, jumping, jumping. All right, so that's how we can do some good work with this. Now, I want to give you folks an extra challenge.

Use pyplot's scatterplot method to add the high and the low here. You can kind of eyeball the high. It looks like it's this special day here in 2012, but I'm really not quite clear on where that low is.

Probably somewhere in here. I mean, we can look at the date. We can print out the date.

We've got these dates, low date and low price, high price and high date. We want to take those two X and Y points and plot them using pyplot's scatterplot method. That's our next challenge.

And I'll let you folks do that, and we'll talk about how we do it in the next video. Take a moment, see if you can figure it out on your own.

Colin Jaffe

Colin Jaffe is a programmer, writer, and teacher with a passion for creative code, customizable computing environments, and simple puns. He loves teaching code, from the fundamentals of algorithmic thinking to the business logic and user flow of application building—he particularly enjoys teaching JavaScript, Python, API design, and front-end frameworks.

Colin has taught code to a diverse group of students since learning to code himself, including young men of color at All-Star Code, elementary school kids at The Coding Space, and marginalized groups at Pursuit. He also works as an instructor for Noble Desktop, where he teaches classes in the Full-Stack Web Development Certificate and the Data Science & AI Certificate.

Colin lives in Brooklyn with his wife, two kids, and many intricate board games.

More articles by Colin Jaffe

How to Learn Python

Master Python with hands-on training. Python is a popular object-oriented programming language used for data science, machine learning, and web development. 

Yelp Facebook LinkedIn YouTube Twitter Instagram