Troubleshooting Your Program

Fine-tune the airfoil plotter.

Understanding the issues

You wanted to graph an airfoil, not a giant greater-than sign. Let’s catalog all of the issues:

  1. The points are not graphed correctly; the points should look like an airfoil
  2. The x-axis and y-axis are flipped, and the numbers are on top of each other
  3. The airfoil name did not display
  4. The background should be white

Matplotlib is supposed to automatically graph (left to right) from negative x to positive x and (down to up) negative y to positive y. Basically, Matplotlib is supposed to graph like a normal graph automatically. Fortunately, addressing issue 1 will also address issue 2. We can address issues 3 and 4 as well.

Fixing the issues

Since we are pulling the airfoil coordinates from a website and getting the coordinates as strs, you might be having an issue where Matplotlib is trying to graph the str of the coordinates, not the coordinates as actual numbers. You can solve this issue by casting each x and y value as float(x.strip()) and float(y.strip()) instead of just writing x.strip() and y.strip(). It is also common to run into issues when splitting a text file at the beginning and/or end of the file. In your case, you clearly have at least one issue at the end: you definitely assigned plot_title to the first line of the file, but it is displayed on the graph as an empty str. There are at least three ways to solve the problem:

  1. Add an additional if statement to verify that line contains more than an empty str (Remember how an empty str is inherently False in Python?)
  2. Add a found_title boolean and add an elif statement to check if found_title is True
  3. Use enumerate() to assign the plot title if the index is 0 (the first line we read) and use a try-except clause to catch the ValueError if the split tries to happen.

All three options are shown below:

Get hands-on with 1200+ tech skills courses.