earthlab / matplotcheck

A python package for checking and testing matplotlib plots. We use this for autograding student assignments but there are many other potential use cases including package testing (for packages with plots)!
https://matplotcheck.readthedocs.io
BSD 3-Clause "New" or "Revised" License
18 stars 8 forks source link

Issue checking x-limits of lines without additional plotted data. #262

Open marty-larocque opened 4 years ago

marty-larocque commented 4 years ago

Some methods of plotting lines with Matplotlib do not yield xy_data. Specifically, base.get_xy() returns None when lines are plotted with some methods.

This causes an issue when calling base.assert_line(), because assert_line() checks that a line spans beyond the x-limits of the plotted data. If no data is plotted (i.e. nothing is plotted other than the line), then these x-limits cannot be determined and an error is thrown.

Here is a gist demonstrating this issue: https://gist.github.com/ryla5068/53762a1b5770ffcb945793274d842904

This is an uncommon case, and could probably go unaddressed. We should decide whether we want to address this issue or not.

lwasser commented 4 years ago

@ryla5068 can you provide some clarification of what methods used to plot return a None value from MPC? the gist doesn't have much information in it - it it just a single plot with a single 1:1 line. What are the conditions that yield a none value? I would assume MPC is looking in the wrong place for the line if it returns none but a line is clearly drawn.

lwasser commented 4 years ago

assert_lines checks for 3 things

  1. the slope
  2. the intercept
  3. the xlims are beyond those of the data in the plot
marty-larocque commented 4 years ago

This happens when two conditions are met:

  1. A line is plotted
  2. No points are plotted (e.g. by using plt.scatter())
  3. assert_line() checks that the xlims are beyond those of the data in the plot

PR #239 does not resolve this issue completely, but it changes assert_line() so that it does not check xlims by default. This makes this issue a far less common edge case.