Skip to content

Commit 9e67dae

Browse files
Added tests for contour linestyles and negative_linestyles
1 parent 95cc6f4 commit 9e67dae

22 files changed

+124
-802
lines changed

lib/matplotlib/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,11 @@ def __getitem__(self, key):
678678

679679
return dict.__getitem__(self, key)
680680

681+
def _get_backend_or_none(self):
682+
"""Get the requested backend, if any, without triggering resolution."""
683+
backend = dict.__getitem__(self, "backend")
684+
return None if backend is rcsetup._auto_backend_sentinel else backend
685+
681686
def __repr__(self):
682687
class_name = self.__class__.__name__
683688
indent = len(class_name) + 1
@@ -1129,9 +1134,8 @@ def use(backend, *, force=True):
11291134
matplotlib.get_backend
11301135
"""
11311136
name = validate_backend(backend)
1132-
# we need to use the base-class method here to avoid (prematurely)
1133-
# resolving the "auto" backend setting
1134-
if dict.__getitem__(rcParams, 'backend') == name:
1137+
# don't (prematurely) resolve the "auto" backend setting
1138+
if rcParams._get_backend_or_none() == name:
11351139
# Nothing to do if the requested backend is already set
11361140
pass
11371141
else:

lib/matplotlib/_mathtext.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,9 @@ def set_names_and_parse_actions():
18821882
self._expression = p.main
18831883
self._math_expression = p.math
18841884

1885+
# To add space to nucleus operators after sub/superscripts
1886+
self._in_subscript_or_superscript = False
1887+
18851888
def parse(self, s, fonts_object, fontsize, dpi):
18861889
"""
18871890
Parse expression *s* using the given *fonts_object* for
@@ -1900,6 +1903,8 @@ def parse(self, s, fonts_object, fontsize, dpi):
19001903
" " * (err.column - 1) + "^",
19011904
str(err)])) from err
19021905
self._state_stack = None
1906+
self._in_subscript_or_superscript = False
1907+
# prevent operator spacing from leaking into a new expression
19031908
self._em_width_cache = {}
19041909
self._expression.resetCache()
19051910
return result[0]
@@ -2108,6 +2113,13 @@ def operatorname(self, s, loc, toks):
21082113
# Add thin space except when followed by parenthesis, bracket, etc.
21092114
hlist_list += [self._make_space(self._space_widths[r'\,'])]
21102115
self.pop_state()
2116+
# if followed by a super/subscript, set flag to true
2117+
# This flag tells subsuper to add space after this operator
2118+
if next_char in {'^', '_'}:
2119+
self._in_subscript_or_superscript = True
2120+
else:
2121+
self._in_subscript_or_superscript = False
2122+
21112123
return Hlist(hlist_list)
21122124

21132125
def start_group(self, s, loc, toks):
@@ -2305,8 +2317,15 @@ def subsuper(self, s, loc, toks):
23052317

23062318
if not self.is_dropsub(last_char):
23072319
x.width += constants.script_space * xHeight
2308-
result = Hlist([nucleus, x])
23092320

2321+
# Do we need to add a space after the nucleus?
2322+
# To find out, check the flag set by operatorname
2323+
spaced_nucleus = [nucleus, x]
2324+
if self._in_subscript_or_superscript:
2325+
spaced_nucleus += [self._make_space(self._space_widths[r'\,'])]
2326+
self._in_subscript_or_superscript = False
2327+
2328+
result = Hlist(spaced_nucleus)
23102329
return [result]
23112330

23122331
def _genfrac(self, ldelim, rdelim, rule, style, num, den):

lib/matplotlib/backends/qt_compat.py

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
- if any of PyQt6, PySide6, PyQt5, or PySide2 have already been
66
imported (checked in that order), use it;
77
- otherwise, if the QT_API environment variable (used by Enthought) is set, use
8-
it to determine which binding to use (but do not change the backend based on
9-
it; i.e. if the Qt5Agg backend is requested but QT_API is set to "pyqt4",
10-
then actually use Qt5 with PyQt5 or PySide2 (whichever can be imported);
8+
it to determine which binding to use;
119
- otherwise, use whatever the rcParams indicate.
1210
"""
1311

@@ -31,18 +29,12 @@
3129
QT_API_PYSIDE6 = "PySide6"
3230
QT_API_PYQT5 = "PyQt5"
3331
QT_API_PYSIDE2 = "PySide2"
34-
QT_API_PYQTv2 = "PyQt4v2"
35-
QT_API_PYSIDE = "PySide"
36-
QT_API_PYQT = "PyQt4" # Use the old sip v1 API (Py3 defaults to v2).
3732
QT_API_ENV = os.environ.get("QT_API")
3833
if QT_API_ENV is not None:
3934
QT_API_ENV = QT_API_ENV.lower()
40-
# Mapping of QT_API_ENV to requested binding. ETS does not support PyQt4v1.
41-
# (https://github.com/enthought/pyface/blob/master/pyface/qt/__init__.py)
42-
_ETS = {
35+
_ETS = { # Mapping of QT_API_ENV to requested binding.
4336
"pyqt6": QT_API_PYQT6, "pyside6": QT_API_PYSIDE6,
4437
"pyqt5": QT_API_PYQT5, "pyside2": QT_API_PYSIDE2,
45-
None: None
4638
}
4739
# First, check if anything is already imported.
4840
if sys.modules.get("PyQt6.QtCore"):
@@ -55,15 +47,10 @@
5547
QT_API = QT_API_PYSIDE2
5648
# Otherwise, check the QT_API environment variable (from Enthought). This can
5749
# only override the binding, not the backend (in other words, we check that the
58-
# requested backend actually matches). Use dict.__getitem__ to avoid
50+
# requested backend actually matches). Use _get_backend_or_none to avoid
5951
# triggering backend resolution (which can result in a partially but
6052
# incompletely imported backend_qt5).
61-
elif (
62-
isinstance(dict.__getitem__(mpl.rcParams, "backend"), str) and
63-
dict.__getitem__(mpl.rcParams, "backend").lower() in [
64-
"qt5agg", "qt5cairo"
65-
]
66-
):
53+
elif (mpl.rcParams._get_backend_or_none() or "").lower().startswith("qt5"):
6754
if QT_API_ENV in ["pyqt5", "pyside2"]:
6855
QT_API = _ETS[QT_API_ENV]
6956
else:
@@ -73,15 +60,12 @@
7360
# fully manually embedding Matplotlib in a Qt app without using pyplot).
7461
elif QT_API_ENV is None:
7562
QT_API = None
63+
elif QT_API_ENV in _ETS:
64+
QT_API = _ETS[QT_API_ENV]
7665
else:
77-
try:
78-
QT_API = _ETS[QT_API_ENV]
79-
except KeyError:
80-
raise RuntimeError(
81-
"The environment variable QT_API has the unrecognized value "
82-
f"{QT_API_ENV!r}; "
83-
f"valid values are {set(k for k in _ETS if k is not None)}"
84-
) from None
66+
raise RuntimeError(
67+
"The environment variable QT_API has the unrecognized value {!r}; "
68+
"valid values are {}".format(QT_API_ENV, ", ".join(_ETS)))
8569

8670

8771
def _setup_pyqt5plus():
@@ -139,7 +123,9 @@ def _isdeleted(obj):
139123
continue
140124
break
141125
else:
142-
raise ImportError("Failed to import any qt binding")
126+
raise ImportError(
127+
"Failed to import any of the following Qt binding modules: {}"
128+
.format(", ".join(_ETS.values())))
143129
else: # We should not get there.
144130
raise AssertionError(f"Unexpected QT_API: {QT_API}")
145131

@@ -186,7 +172,7 @@ def _devicePixelRatioF(obj):
186172
except AttributeError:
187173
pass
188174
try:
189-
# Not available on Qt4 or some older Qt5.
175+
# Not available on older Qt5.
190176
# self.devicePixelRatio() returns 0 in rare cases
191177
return obj.devicePixelRatio() or 1
192178
except AttributeError:
@@ -200,7 +186,7 @@ def _setDevicePixelRatio(obj, val):
200186
This can be replaced by the direct call when we require Qt>=5.6.
201187
"""
202188
if hasattr(obj, 'setDevicePixelRatio'):
203-
# Not available on Qt4 or some older Qt5.
189+
# Not available on older Qt5.
204190
obj.setDevicePixelRatio(val)
205191

206192

lib/matplotlib/contour.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,11 +1757,11 @@ def _initialize_x_y(self, z):
17571757
iterable is shorter than the number of contour levels
17581758
it will be repeated as necessary.
17591759
1760-
negative_linestyles : *None* or str, optional
1760+
negative_linestyles : None or str, optional
17611761
{'solid', 'dashed', 'dashdot', 'dotted'}
17621762
*Only applies to* `.contour`.
17631763
1764-
If *negative_linestyles* is *None*, the default is 'dashed' for
1764+
If *negative_linestyles* is None, the default is 'dashed' for
17651765
negative contours.
17661766
17671767
*negative_linestyles* can also be an iterable of the above

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2195,7 +2195,7 @@ def polar(*args, **kwargs):
21952195
# requested, ignore rcParams['backend'] and force selection of a backend that
21962196
# is compatible with the current running interactive framework.
21972197
if (rcParams["backend_fallback"]
2198-
and dict.__getitem__(rcParams, "backend") in (
2198+
and rcParams._get_backend_or_none() in (
21992199
set(_interactive_bk) - {'WebAgg', 'nbAgg'})
22002200
and cbook._get_running_interactive_framework()):
22012201
dict.__setitem__(rcParams, "backend", rcsetup._auto_backend_sentinel)
Binary file not shown.
Binary file not shown.

lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_30.svg

Lines changed: 0 additions & 188 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)