Making a tall, skinny plot in Mathematica

Yesterday’s post included this plot:

Rescaled Moon and Earth orbit

I figured it was worth a quick post to show how I made it.

I had already done most of the work back in 2022 in a Mathematica notebook I made to support my original orbital curvature post. So I copied the pertinent calculations from that notebook, pasted them into a new one, and made the adjustments necessary to produce the plot. Here’s the new notebook:

The bottom half of the notebook is where the plotting commands are. The key items are:

To get the image out of the notebook, I right-clicked on it, selected Save Graphic As… from the popup menu, and chose SVG as the format. That’s why the plot stays smooth if you zoom in on it.


Distorted plots

Rhett Allain, physics professor and blogger, published a nice article today about the Moon’s orbit. It follows largely the same line of reasoning as my post on the same topic (and the various write-ups I linked to in that post) from a few years ago. I nodded my head as I read through it, until I got to a plot at the end of the article.

For much of the article, Allain complains about how the orbit of the Moon as it and the Earth make their way around the Sun is often distorted in textbooks. Like this, which is a frame from an animated GIF in the article.

Distorted orbits around the Sun

In this image, the Earth-Moon distance is exaggerated, and it looks like the Moon curves away from the Sun when it’s between the Earth and the Sun. To show that this is wrong, he plots portions of the Moon and Earth orbits without exaggerating the Moon-Earth distance:

Allain plot of Moon and Earth orbits

Forgive me, but what the actual fuck? How can you spend over 1000 words complaining about graphical distortions and then produce this? Sure, it’s not the same distortion he was complaining about, but still. The whole point of the article was to show that the Moon’s path over the course of an Earth year is a sort of wobbly circle around the Sun. The arcs in this plot are nowhere near circular.

Here’s a properly scaled version of Allain’s plot:

Rescaled Moon and Earth orbit

Yes, the plot is really tall and skinny. It has to be to avoid distorting the paths. Note that the grids are square and represent the same distance in each direction.

We all know how this happened. The range of the x data is very small compared to the range of the y data, but because the plotting software defaults to a landscape-style graph, the paths come out looking like arcs of very wide ellipses. Unless the person running the software steps in to make sure x and y distances are drawn to the same scale.

I could write a post like this almost every day. So many people accept the defaults of their graphing software without thinking about how one or two small tweaks could make their plots so much better.


Too dumb for AI

I’ll admit that the first thing I looked into regarding yesterday’s “Super Intelligence” meeting at the White House was whether Tim Cook was there. He wasn’t, which was probably a relief to Tim, even though it’s also an admission that Apple isn’t considered a player in AI. By anyone, not even the idiots in the Trump administration.

You’ve probably seen the stupid misspelling above Trump’s signature on the “morally binding” agreement that came out of the meeting.

Signature page

Yes, he signed it as the “President of the Unites States” and then proudly posted it to Truth Social. I can’t imagine the agreement means anything, as you’d be hard-pressed to find a single moral shared among the people in the meeting. I will say, though, that Jensen Huang’s signature is pretty spiffy.

As for who was at the meeting, Trump also posted this seating chart, which hurts to look at:

Seating chart

Click the image to see it at full size, if you dare. Also, don’t feel obligated to follow either of the Truth Social links; I’m including them only because I feel an obligation to give credit—or in this case blame.

Lots of the images Trump posts are AI-generated, but I find it hard to believe that any AI system would produce something with this many graphical errors:

And then there’s the best one:

The meeting probably would have been better for all of us if this had been so.


A small probability correction

This short video appeared in my YouTube feed last week. It’s from Hannah Fry, whom you probably know from her appearances on Numberphile and other STEM-oriented stuff. If you’re in the UK, you’ve may have seen her on the BBC, too.

The short presents a classic problem in conditional probability, but the answer she comes up with is wrong. It’s a good estimate, and it’s the same answer I got when I stopped the video and tried to work it out in my head, but it’s still wrong. By just a little bit.

Here’s the problem: There’s a disease that affects 1 in 1,000 people. A test for the disease is perfect in one sense but imperfect in another. If you have the disease, the test will return a positive result 100% of the time. If you don’t have the disease, the test will return a negative result 95% of the time but a positive result 5% of the time. If you have the test and the result is positive, what is the probability you have the disease?

What makes this a classic problem is that it presents you with conditional probability in one sense (the probability of a positive test given that you have the disease) and asks for a conditional probability in the opposite sense (the probability that you have the disease given that your test was positive). The solution combines the definition of conditional probability, the commutative property of intersections, and the law of total probability.

Let’s define some events. D is you having the disease, and T is you getting a positive test result. Putting a horizontal bar over these indicates not having the disease and not testing positive (i.e., testing negative), respectively. Therefore

P(D)=0.001P(D—)=0.999P(T∣D)=1P(T—∣D—)=0.95P(T∣D—)=0.05

The vertical bars are read as “given,” meaning the event after the bar is the condition. What we’ve been asked to find is P(D∣T). Let’s work it out.

By the definition of conditional probability, we can say

P(D∩T)=P(D∣T)P(T)

where ∩ means the intersection of the two events. So

P(D∣T)=P(D∩T)P(T)

Because the intersection of events is commutative

P(D∩T)=P(T∩D)=P(T∣D)P(D)

Both terms on the right-hand side of this equation are known, so we can say

P(D∣T)=(1)(0.001)P(T)

Since D and D— are mutually exclusive and collectively exhaustive, the law of total probability says

P(T)=P(T∣D)P(D)+P(T∣D—)P(D—)=(1)(0.001)+(0.05)(0.999)=0.05095

So

P(D∣T)=0.0010.05095=0.019627

which is, as I said, pretty close to the 2% answer in the video but not exactly.

This formal approach is how you’re taught to solve problems like this in an introductory probability class, but Dr. Fry and I used a more concrete method to get our nearly correct answers. Here’s what we did:

Imagine 1,000 typical people. Of these, 1 should have the disease (correct) and 50 should test positive (incorrect). That tells us that 1 in 50, or 2%, of the people who test positive will have the disease. Here’s a screenshot from the video that matches this calculation:

Illustration using 1000 people

What makes this calculation wrong is that it implicitly assumes that 5% of everyone will test positive, not 5% of only those who don’t have the disease. The number who will test positive should be 5% of 999, which is 49.95, plus the 1 who does have the disease. So 1 in 50.95, or 1.9627%, of those who test positive will have the disease. This answer matches that of the formal approach.

This is somewhat unsatisfying, though, as the purpose of this “imagine a bunch of typical people” method is to have all the people counts be integers. Although the numbers work out when you get to the end, it’s distracting to litter the discussion with fractional people. You can get around this by imagining more people—a million, say—but then all the numbers get bigger: 1,000 people with the disease and 49,950 false positives. This isn’t a problem for the kind of people who read this blog but isn’t so great for the more general audience Dr. Fry is addressing.

Personally, I would have been OK with her saying that 5% of 999 is almost 50, so the number who test positive is nearly 51. And 1 out of 51 is just under 2%—call it 2% in round figures. You still make the point that it’s way less than 95% and that problems like this require some care.