Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removal of matplotlib<3 compatibility checks #2665

Merged
merged 7 commits into from Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 1 addition & 9 deletions obspy/core/tests/test_channel.py
Expand Up @@ -17,7 +17,6 @@
import numpy as np
from matplotlib import rcParams

from obspy.core.util import MATPLOTLIB_VERSION
from obspy.core.util.testing import ImageComparison
from obspy import read_inventory
from obspy.core.inventory import Channel, Equipment
Expand All @@ -42,17 +41,10 @@ def test_response_plot(self):
"""
Tests the response plot.
"""
# Bug in matplotlib 1.4.0 - 1.4.x:
# See https://github.com/matplotlib/matplotlib/issues/4012
reltol = 1.0
if [1, 4, 0] <= MATPLOTLIB_VERSION <= [1, 5, 0]:
reltol = 2.0

cha = read_inventory()[0][0][0]
with warnings.catch_warnings(record=True):
warnings.simplefilter("ignore")
with ImageComparison(self.image_dir, "channel_response.png",
reltol=reltol) as ic:
with ImageComparison(self.image_dir, "channel_response.png") as ic:
rcParams['savefig.dpi'] = 72
cha.plot(0.005, outfile=ic.name)

Expand Down
10 changes: 2 additions & 8 deletions obspy/core/tests/test_inventory.py
Expand Up @@ -179,18 +179,12 @@ def test_response_plot(self):
"""
Tests the response plot.
"""
# Bug in matplotlib 1.4.0 - 1.4.x:
# See https://github.com/matplotlib/matplotlib/issues/4012
reltol = 1.0
if [1, 4, 0] <= MATPLOTLIB_VERSION <= [1, 5, 0]:
reltol = 2.0

inv = read_inventory()
t = UTCDateTime(2008, 7, 1)
with warnings.catch_warnings(record=True):
warnings.simplefilter("ignore")
with ImageComparison(self.image_dir, "inventory_response.png",
reltol=reltol) as ic:
with ImageComparison(self.image_dir,
"inventory_response.png") as ic:
rcParams['savefig.dpi'] = 72
inv.plot_response(0.01, output="ACC", channel="*N",
station="[WR]*", time=t, outfile=ic.name)
Expand Down
9 changes: 1 addition & 8 deletions obspy/core/tests/test_network.py
Expand Up @@ -126,18 +126,11 @@ def test_response_plot(self):
"""
Tests the response plot.
"""
# Bug in matplotlib 1.4.0 - 1.4.x:
# See https://github.com/matplotlib/matplotlib/issues/4012
reltol = 1.0
if [1, 4, 0] <= MATPLOTLIB_VERSION <= [1, 5, 0]:
reltol = 2.0

net = read_inventory()[0]
t = UTCDateTime(2008, 7, 1)
with warnings.catch_warnings(record=True):
warnings.simplefilter("ignore")
with ImageComparison(self.image_dir, "network_response.png",
reltol=reltol) as ic:
with ImageComparison(self.image_dir, "network_response.png") as ic:
rcParams['savefig.dpi'] = 72
net.plot_response(0.002, output="DISP", channel="B*E",
time=t, outfile=ic.name)
Expand Down
20 changes: 3 additions & 17 deletions obspy/core/tests/test_response.py
Expand Up @@ -22,7 +22,6 @@
from obspy import UTCDateTime, read_inventory
from obspy.core.inventory.response import (
_pitick2latex, PolesZerosResponseStage, PolynomialResponseStage, Response)
from obspy.core.util import MATPLOTLIB_VERSION
from obspy.core.util.misc import CatchOutput
from obspy.core.util.obspy_types import ComplexWithUncertainties
from obspy.core.util.testing import ImageComparison
Expand Down Expand Up @@ -126,17 +125,11 @@ def test_response_plot(self):
"""
Tests the response plot.
"""
# Bug in matplotlib 1.4.0 - 1.4.x:
# See https://github.com/matplotlib/matplotlib/issues/4012
reltol = 1.0
if [1, 4, 0] <= MATPLOTLIB_VERSION <= [1, 5, 0]:
reltol = 2.0

resp = read_inventory()[0][0][0].response
with warnings.catch_warnings(record=True):
warnings.simplefilter("ignore")
with ImageComparison(self.image_dir, "response_response.png",
reltol=reltol) as ic:
with ImageComparison(self.image_dir,
"response_response.png") as ic:
rcParams['savefig.dpi'] = 72
resp.plot(0.001, output="VEL", start_stage=1, end_stage=3,
outfile=ic.name)
Expand All @@ -145,18 +138,11 @@ def test_response_plot_degrees(self):
"""
Tests the response plot in degrees.
"""
# Bug in matplotlib 1.4.0 - 1.4.x:
# See https://github.com/matplotlib/matplotlib/issues/4012
reltol = 1.0
if [1, 4, 0] <= MATPLOTLIB_VERSION <= [1, 5, 0]:
reltol = 2.0

resp = read_inventory()[0][0][0].response
with warnings.catch_warnings(record=True):
warnings.simplefilter("ignore")
with ImageComparison(self.image_dir,
"response_response_degrees.png",
reltol=reltol) as ic:
"response_response_degrees.png") as ic:
rcParams['savefig.dpi'] = 72
resp.plot(0.001, output="VEL", start_stage=1, end_stage=3,
plot_degrees=True, outfile=ic.name)
Expand Down
19 changes: 2 additions & 17 deletions obspy/core/tests/test_station.py
Expand Up @@ -17,7 +17,6 @@
from matplotlib import rcParams

from obspy import read_inventory, UTCDateTime
from obspy.core.util import MATPLOTLIB_VERSION
from obspy.core.util.testing import ImageComparison


Expand All @@ -37,36 +36,22 @@ def test_response_plot(self):
"""
Tests the response plot.
"""
# Bug in matplotlib 1.4.0 - 1.4.x:
# See https://github.com/matplotlib/matplotlib/issues/4012
reltol = 1.0
if [1, 4, 0] <= MATPLOTLIB_VERSION <= [1, 5, 0]:
reltol = 2.0

sta = read_inventory()[0][0]
with warnings.catch_warnings(record=True):
warnings.simplefilter("ignore")
with ImageComparison(self.image_dir, "station_response.png",
reltol=reltol) as ic:
with ImageComparison(self.image_dir, "station_response.png") as ic:
rcParams['savefig.dpi'] = 72
sta.plot(0.05, channel="*[NE]", outfile=ic.name)

def test_response_plot_degrees(self):
"""
Tests the response plot.
"""
# Bug in matplotlib 1.4.0 - 1.4.x:
# See https://github.com/matplotlib/matplotlib/issues/4012
reltol = 1.0
if [1, 4, 0] <= MATPLOTLIB_VERSION <= [1, 5, 0]:
reltol = 2.0

sta = read_inventory()[0][0]
with warnings.catch_warnings(record=True):
warnings.simplefilter("ignore")
with ImageComparison(self.image_dir,
"station_response_degrees.png",
reltol=reltol) as ic:
"station_response_degrees.png") as ic:
rcParams['savefig.dpi'] = 72
sta.plot(0.05, channel="*[NE]", plot_degrees=True,
outfile=ic.name)
Expand Down
44 changes: 6 additions & 38 deletions obspy/core/util/testing.py
Expand Up @@ -23,7 +23,7 @@
import numpy as np
from lxml import etree

from obspy.core.util.base import NamedTemporaryFile, MATPLOTLIB_VERSION
from obspy.core.util.base import NamedTemporaryFile
from obspy.core.util.misc import MatplotlibBackend

# this dictionary contains the locations of checker routines that determine
Expand Down Expand Up @@ -321,13 +321,8 @@ def __init__(self, image_path, image_name, reltol=1,
self.plt_close_all_exit = plt_close_all_exit
self.no_uploads = no_uploads

if (MATPLOTLIB_VERSION < [1, 4, 0] or
(MATPLOTLIB_VERSION[:2] == [1, 4] and style is None)):
# No good style support.
self.style = None
else:
import matplotlib.style as mstyle
self.style = mstyle.context(style or 'classic')
import matplotlib.style as mstyle
self.style = mstyle.context(style or 'classic')

# Adjust the tolerance based on the matplotlib version. This works
# well enough and otherwise testing is just a pain.
Expand All @@ -336,33 +331,9 @@ def __init__(self, image_path, image_name, reltol=1,
# which is after https://github.com/matplotlib/matplotlib/issues/7905
# has been fixed.
#
# Thus test images should accurate for matplotlib >= 2.0.1 anf
# fairly accurate for matplotlib 1.5.x.
# Thus test images should accurate for matplotlib >= 2.0.1.
if adjust_tolerance:
# Really old versions.
if MATPLOTLIB_VERSION < [1, 3, 0]:
self.tol *= 30
# 1.3 + 1.4 have slightly different text positioning mostly.
elif [1, 3, 0] <= MATPLOTLIB_VERSION < [1, 5, 0]:
self.tol *= 15
# A few plots with mpl 1.5 have ticks and axis slightl shifted.
# This is especially true for ticks with exponential numbers.
# Thus the tolerance also has to be a bit higher here.
elif [1, 5, 0] <= MATPLOTLIB_VERSION < [2, 0, 0]:
self.tol *= 5.0
# Matplotlib 2.0.0 has a bug with the tick placement. This is
# fixed in 2.0.1 but the tolerance for 2.0.0 has to be much
# higher. 12 is an empiric value. The tick placement potentially
# influences the axis locations and then the misfit is really
# quite high.
elif [2, 0, 0] <= MATPLOTLIB_VERSION < [2, 0, 1]:
self.tol *= 12
# Some section waveform plots made on 2.2.2 have offset ticks on
# 2.0.2, so up tolerance a bit (see #2493)
elif MATPLOTLIB_VERSION < [2, 1]:
self.tol *= 5

# One last pass depending on the freetype version.
# Adjusts tolerance depending on the freetype version.
# XXX: Should eventually be handled differently!
try:
from matplotlib import ft2font
Expand Down Expand Up @@ -398,10 +369,7 @@ def __enter__(self):
rcdefaults()
if self.style is not None:
self.style.__enter__()
if MATPLOTLIB_VERSION >= [2, 0, 0]:
default_font = 'DejaVu Sans'
else:
default_font = 'Bitstream Vera Sans'
default_font = 'DejaVu Sans'
rcParams['font.family'] = default_font
with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings('always', 'findfont:.*')
Expand Down
10 changes: 2 additions & 8 deletions obspy/imaging/maps.py
Expand Up @@ -423,10 +423,7 @@ def linspace2(val1, val2, n):
raise ValueError(msg)

# draw coast lines, country boundaries, fill continents.
if MATPLOTLIB_VERSION >= [2, 0, 0]:
ax.set_facecolor(water_fill_color)
else:
ax.set_axis_bgcolor(water_fill_color)
ax.set_facecolor(water_fill_color)
# newer matplotlib errors out if called with empty coastline data (no
# coast on map)
if np.size(getattr(bmap, 'coastsegs', [])):
Expand Down Expand Up @@ -701,10 +698,7 @@ def plot_cartopy(lons, lats, size, color, labels=None, projection='global',
_CARTOPY_FEATURES[resolution] = (borders, land, ocean)

# Draw coast lines, country boundaries, fill continents.
if MATPLOTLIB_VERSION >= [2, 0, 0]:
map_ax.set_facecolor(water_fill_color)
else:
map_ax.set_axis_bgcolor(water_fill_color)
map_ax.set_facecolor(water_fill_color)
map_ax.add_feature(ocean, facecolor=water_fill_color)
map_ax.add_feature(land, facecolor=continent_fill_color)
map_ax.add_feature(borders, edgecolor='0.75')
Expand Down
7 changes: 1 addition & 6 deletions obspy/imaging/scripts/mopad.py
Expand Up @@ -2368,12 +2368,7 @@ def pa_plot(self, kwargs):
size = min(width, height)

fig = plt.figure(34, figsize=(size, size))
# TODO remove once minimum required matplotlib version reaches 2.0
# see matplotlib/matplotlib#5501
if MATPLOTLIB_VERSION < [2, 0]:
axis_facecolor_kwargs = dict(axisbg='#d5de9c')
else:
axis_facecolor_kwargs = dict(facecolor='#d5de9c')
axis_facecolor_kwargs = dict(facecolor='#d5de9c')
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True,
**axis_facecolor_kwargs)

Expand Down
4 changes: 0 additions & 4 deletions obspy/imaging/source.py
Expand Up @@ -16,7 +16,6 @@
import numpy as np
from matplotlib.cm import get_cmap

from obspy.core.util import MATPLOTLIB_VERSION
from obspy.core.event.source import farfield
from obspy.imaging.scripts.mopad import MomentTensor, BeachBall
from obspy.imaging.mopad_wrapper import beach
Expand Down Expand Up @@ -268,9 +267,6 @@ def _plot_radiation_pattern_quiver(ax3d, ned_mt, type):
:param type: 'P' or 'S' (P or S wave).
"""
import matplotlib.pyplot as plt
if MATPLOTLIB_VERSION < [1, 4]:
msg = ("Matplotlib 3D quiver plot needs matplotlib version >= 1.4.")
raise ImportError(msg)

type = type.upper()
if type not in ("P", "S"):
Expand Down
9 changes: 4 additions & 5 deletions obspy/imaging/tests/test_ppsd.py
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

from obspy.core.util.testing import ImageComparison, MATPLOTLIB_VERSION
from obspy.core.util.testing import ImageComparison
from obspy.signal.tests.test_spectral_estimation import _get_ppsd


Expand All @@ -28,6 +28,9 @@ def test_ppsd_plot(self):
# Catch underflow warnings due to plotting on log-scale.
with np.errstate(all='ignore'):
with ImageComparison(self.path, 'ppsd.png', reltol=1.5) as ic:
# mpl < 2.2 has slightly offset ticks/ticklabels, so it needs
# a higher `reltol` tolerance
# (see e.g. http://tests.obspy.org/102260)
self.ppsd.plot(
show=False, show_coverage=True, show_histogram=True,
show_percentiles=True, percentiles=[75, 90],
Expand All @@ -43,11 +46,7 @@ def test_ppsd_plot_frequency(self):
"""
Test plot of ppsd example data, normal (non-cumulative) style.
"""
# mpl < 2.2 has slightly offset ticks/ticklabels, so needs a higher
# tolerance (see e.g. http://tests.obspy.org/102260)
reltol = 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline this in the ImageComparison call.

if MATPLOTLIB_VERSION < [2, 2]:
reltol = 4
# Catch underflow warnings due to plotting on log-scale.
with np.errstate(all='ignore'):
with ImageComparison(self.path, 'ppsd_freq.png',
Expand Down
3 changes: 0 additions & 3 deletions obspy/imaging/tests/test_source.py
Expand Up @@ -6,7 +6,6 @@
import unittest

from obspy.imaging.source import plot_radiation_pattern
from obspy.core.util.base import MATPLOTLIB_VERSION


class RadPatternTestCase(unittest.TestCase):
Expand All @@ -19,8 +18,6 @@ def setUp(self):
self.path = path
self.image_dir = os.path.join(os.path.dirname(__file__), 'images')

@unittest.skipIf(MATPLOTLIB_VERSION < [1, 4],
'matplotlib >= 1.4 needed for 3D quiver plot.')
def test_farfield_with_quiver(self):
"""
Tests to plot P/S wave farfield radiation pattern
Expand Down
6 changes: 1 addition & 5 deletions obspy/imaging/util.py
Expand Up @@ -16,7 +16,6 @@
from matplotlib.ticker import FuncFormatter

from obspy import UTCDateTime
from obspy.core.util import MATPLOTLIB_VERSION


def _seconds_to_days(sec):
Expand Down Expand Up @@ -97,10 +96,7 @@ class ObsPyAutoDateFormatter(AutoDateFormatter):
def __init__(self, *args, **kwargs):
# the root class of AutoDateFormatter (TickHelper) is an old style
# class prior to matplotlib version 1.2
if MATPLOTLIB_VERSION < [1, 2, 0]:
AutoDateFormatter.__init__(self, *args, **kwargs)
else:
super(ObsPyAutoDateFormatter, self).__init__(*args, **kwargs)
super(ObsPyAutoDateFormatter, self).__init__(*args, **kwargs)
# Reset the scale to make it reproducible across matplotlib versions.
self.scaled = {}
self.scaled[1.0] = '%b %d %Y'
Expand Down