Graphing Atmosphere as Secant
00:00 New feature, new copy of the code. Yeah, still not a good idea. All right, let me scroll down.
00:07 Adding yet another line to our graph is probably going to be messy. There’s already a lot going on there. So instead I want to put the air mass info in a paired plot above our graph.
00:18 Spoiler alert, there’s Matplotlib grumbling in your future. So you’ll remember I used a context approach before. Matplotlib can also have a quasi-object approach.
00:30
You’ll see why I said quasi in a second. The subplots()
call does a few things, all of which involve multiple graphs in the way I’m calling it here with the first argument.
00:40
Two, that means to create two graphs on the same canvas since I didn’t specify otherwise. There’ll be one over top. The other, what comes back from subplots()
is a reference to the figure, meaning the drawing canvas and a tuple.
00:55 The tuple contains each of the graphs, except it isn’t quite the graphs. Matplotlib calls these the axes. Yeah, plural. There’s a relationship between an axes plural and a graph as they kind of go together.
01:07
But there are odd corner cases where you think you need one and you actually need the other. But for our purposes, this is going to be good enough. So there are a few arguments to subplots()
that I need to go over.
01:17
The figsize
argument changes the size of the overall rendering window. It gets specified in inches. Yeah, that horrifies me. Anyhow. The sharex
argument says that the two graphs will have a synchronized X-axis, which in our case is the times.
01:34
And the height_ratios
argument allows you to change the relative sizes of the two graphs. The given value here states the bottom graph should be twice the height of the top graph.
01:45
This is actually kind of nice as Matplotlib works out the sizes for you, rather than you having to fiddle with pixel values to put a title over the top of both of our graphs, you use the suptitle()
call on the figure, and then the subplots_adjust()
call allows you to change the amount of spacing between the two graphs in the figure.
02:05
Ask me why this is a separate context-based function call instead of, I don’t know, an argument to figure()
or even subplots()
.
02:13 Go ahead, ask me. Grumble, grumble. Matplotlib grumble. Alright, scrolling down.
02:22
This chunk is almost the same as the graphing code in version two, but instead of operating directly using functions that affect the context, now I’m calling methods on the bottom subgraph returned in the tuple from subplots()
.
02:35
I believe I promised more grumbling. Did you think I was done? Note here that the xlim()
, ylim()
, xlabel()
and ylabel()
functions don’t have the same names on the subgraphs as they did in the context style.
02:47
In the previous version of the code. You have to call .set_xlim()
, .set_ylim()
, etc. Yeah, that’s not confusing at all.
02:57
And here is what you came here for. The air mass estimate based on the secant of the target, which I then plot as a line in the top graph. Then I set the Y-axis label, add a legend showing this beast and call plot()
.
03:13 Like before. I’m going to skip the actual command line and I’ll just skip to some of the output.
03:19 And here it is, the air mass graph is on top and the target graph is below. This time around I graphed Betelgeuse six and seven and eight and bunch. And what you can see here is that the air mass is thickest just as Betelgeuse crests the horizon.
03:36 The viewing gets better after that. But unfortunately for looking at this particular target, the air mass isn’t going to be the problem. The sun is. Note that negative air mass isn’t really a thing, but the library is just doing the trig.
03:50 So if the target is below the horizon, you get a negative value. Something tells me that the big chunk of rock that you’re standing on will be harder to see through than any amount of air.
04:01 Alright, it’s been quite a journey. Next up is the summary and a few pointers at other libraries. Then I’ll meet you at the restaurant at the end of the universe.
Become a Member to join the conversation.