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

Create Vignette - Documentation for multi axis figures #116

Open lwasser opened 5 years ago

lwasser commented 5 years ago

https://github.com/earthlab/autograding-notebooks/blob/master/notebooks/ea-homework-for-timeseries-raster.ipynb

# Plot the data - place your final data here

# BEGIN SOLUTION

# Add plot code only for plots 1 and 2 here
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 10))
ep.plot_rgb(naip_2017_crop,
            rgb=[0, 1, 2],
            extent=naip_2015_ext,
            title="Homework PLOT 1: NAIP 2017 Post Fire RGB Image\n Cropped",
            ax=ax1)
fire_bound_utmz13.plot(ax=ax1, color='None',
                       edgecolor='white', linewidth=2)

# plot 2017 cropped data
ep.plot_rgb(naip_2017_crop,
            rgb=[3, 0, 1],
            extent=naip_2015_ext,
            title="Homework PLOT 2: NAIP 2017 Post Fire CIR Image",
            ax=ax2)
fire_bound_utmz13.plot(ax=ax2, color='None',
                       edgecolor='white', linewidth=2)
plt.show()
# END SOLUTION

### DO NOT REMOVE LINE BELOW ###
raster_plot = nb.convert_axes(plt, which_axes="all")
# Here i have to create a set of tests for a plot with subplots. this might involve loops
hw_raster_plot1 = ra.RasterTester(raster_plot[0])
hw_raster_plot2 = ra.RasterTester(raster_plot[1])

test_axis_off_plot1 = [hw_raster_plot1.assert_axis_off(),
                       1,
                       "RGB Image: Axis format looks great!",
                       "RGB Image: Looks like your axis is still on. Please turn axis_off."]

test_axis_off_plot2 = [hw_raster_plot2.assert_axis_off(),
                       1,
                       "CIR Image: Axis format looks great!",
                       "CIR Image: Looks like your axis is still on. Please turn axis_off."]

# Check plot extent ?? -- not sure i can do that yet with MPC functionality but it would be easy to add

# Check title
test_title_plot1 = [hw_raster_plot1.assert_title_contains(["NAIP", "2017", "RGB"]),
                    2,
                    "Title looks good",
                    "oops check your title"]
test_title_plot2 = [hw_raster_plot2.assert_title_contains(["NAIP", "2017", "CIR"]),
                    2,
                    "Title looks good",
                    "oops check your title"]

run_all_tests([test_axis_off_plot1, 
               test_axis_off_plot2, 
               test_title_plot1, 
               test_title_plot2])
nkorinek commented 4 years ago

@lwasser for this Vignette, we've been talking recently about just using the ax object instead of using the nb.convert_axes() function. Would you like me to show both, or is there one we want to promote as the "correct" way of checking this?

lwasser commented 4 years ago

i think we want to use the ax approach in our docs. but in each vignette we can add a note to show what the notebook implementation would look like. i think that makes sense for the time being because we can't assume everyone is using notebooks. We could then have an entire vignette dedicated to notebooks

nkorinek commented 4 years ago

Addressed here: https://github.com/earthlab/matplotcheck/pull/241