Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Exploring Astrophysics in Python With pandas and Matplotlib (Summary)

Congratulations on completing the course! You used real world calculation problems from astronomy and astrophysics to practice with several third-party data and science libraries.

In the video course you learned about:

  • Astrophysics
  • Using the pint library to do calculations with values that have units
  • Visualizing black body radiation with a Matplotlib historgram
  • Charting hundreds of stars from a panda’s DataFrame in a HR diagram

RealPython has lots more content on pandas and Matplotlib:

Download

Course Slides (.pdf)

6.6 MB
Download

Sample Code (.zip)

33.4 KB

00:00 In the previous lesson, I showed you how to graph a Hertzsprung-Russell Diagram. This lesson is the summary and contains a few pointers to other libraries.

00:09 This course has been all about exploring different aspects of astrophysics using Python code. It started out by looking at scientific units. Accidentally using incompatible units has caused massive public mistakes in the space program.

00:22 Using a library like pint to attach unit information to your data can be very useful. Pint allows you to do math with the defined quantities, and importantly will check if you do something that shouldn’t be allowed, like adding a velocity to an acceleration.

00:37 One of the kings of the data science world is the fuzzy little bear known as pandas. This is a third-party library for doing data manipulation where you store and manage your data in a tabular form. Like a spreadsheet, you have rows and columns of data which you can build yourself or read out of a file like a CSV.

00:56 One powerful aspect of pandas and the related NumPy library is the ability to do math calculations across an entire column in a single line of code.

01:06 And once you’ve got the data, you can filter it to conditionally change some parts or display a subset of the values. Having data is great, but looking at those numbers can make your eyes water.

01:17 Visualizing your data can be helpful in finding patterns and understanding it better. The Matplotlib library is a graphing library which interacts well with pandas and NumPy.

01:28 It has a large range of charts including histograms, bar charts, scatter plots, and more. Once the graph has been prepared, the primitives that Matplotlib uses to build the display can be accessed.

01:40 These primitives are called “patches” and for a histogram or bar chart, they’re the rectangles that make up the graph.

01:46 By being able to get at the patches, you can fine-tune your graph and conditionally change their results.

01:53 If you want to learn more about pandas, this content is a good place to start. It’s available as both a tutorial and a video course. To dig more into Matplotlib and visualizing pandas DataFrames, this tutorial and video course can help you out,

02:07 or if you want to just concentrate on the Matplotlib aspect, this guide may be useful for you.

02:14 That’s all for now. Juliano and I hope you enjoyed the course.

Become a Member to join the conversation.