8000 Small style fixes. · matplotlib/matplotlib@075ff09 · GitHub
[go: up one dir, main page]

Skip to content

Commit 075ff09

Browse files
committed
Small style fixes.
1 parent 2e921df commit 075ff09

File tree

21 files changed

+77
-105
lines changed
  • doc/devel
    • MEP
  • examples
  • lib
  • 21 files changed

    +77
    -105
    lines changed

    doc/devel/MEP/MEP26.rst

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -34,7 +34,7 @@ Detailed description
    3434
    ====================
    3535

    3636
    Currently, the look and appearance of existing artist objects (figure,
    37-
    axes, Line2D etc...) can only be updated via ``set_`` and ``get_`` methods
    37+
    axes, Line2D, etc.) can only be updated via ``set_`` and ``get_`` methods
    3838
    on the artist object, which is quite laborious, especially if no
    3939
    reference to the artist(s) has been stored. The new style sheets
    4040
    introduced in 1.4 allow styling before a plot is created, but do not
    @@ -51,7 +51,7 @@ of primitives.
    5151
    The new methodology would require development of a number of steps:
    5252

    5353
    - A new stylesheet syntax (likely based on CSS) to allow selection of
    54-
    artists by type, class, id etc...
    54+
    artists by type, class, id, etc.
    5555
    - A mechanism by which to parse a stylesheet into a tree
    5656
    - A mechanism by which to translate the parse-tree into something
    5757
    which can be used to update the properties of relevant

    doc/devel/documenting_mpl.rst

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -675,7 +675,7 @@ Keyword arguments
    675675

    676676
    Since Matplotlib uses a lot of pass-through ``kwargs``, e.g., in every function
    677677
    that creates a line (`~.pyplot.plot`, `~.pyplot.semilogx`, `~.pyplot.semilogy`,
    678-
    etc...), it can be difficult for the new user to know which ``kwargs`` are
    678+
    etc.), it can be difficult for the new user to know which ``kwargs`` are
    679679
    supported. Matplotlib uses a docstring interpolation scheme to support
    680680
    documentation of every function that takes a ``**kwargs``. The requirements
    681681
    are:

    examples/event_handling/pick_event_demo.py

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -4,8 +4,8 @@
    44
    ===============
    55
    66
    You can enable picking by setting the "picker" property of an artist
    7-
    (for example, a matplotlib Line2D, Text, Patch, Polygon, AxesImage,
    8-
    etc...)
    7+
    (for example, a Matplotlib Line2D, Text, Patch, Polygon, AxesImage,
    8+
    etc.)
    99
    1010
    There are a variety of meanings of the picker property:
    1111

    examples/misc/custom_projection.py

    Lines changed: 2 additions & 8 deletions
    Original file line numberDiff line numberDiff line change
    @@ -270,14 +270,8 @@ def format_coord(self, lon, lat):
    270270
    In this case, we want them to be displayed in degrees N/S/E/W.
    271271
    """
    272272
    lon, lat = np.rad2deg([lon, lat])
    273-
    if lat >= 0.0:
    274-
    ns = 'N'
    275-
    else:
    276-
    ns = 'S'
    277-
    if lon >= 0.0:
    278-
    ew = 'E'
    279-
    else:
    280-
    ew = 'W'
    273+
    ns = 'N' if lat >= 0.0 else 'S'
    274+
    ew = 'E' if lon >= 0.0 else 'W'
    281275
    return ('%f\N{DEGREE SIGN}%s, %f\N{DEGREE SIGN}%s'
    282276
    % (abs(lat), ns, abs(lon), ew))
    283277

    examples/text_labels_and_annotations/usetex_fonteffects.py

    Lines changed: 7 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -15,12 +15,13 @@ def setfont(font):
    1515

    1616

    1717
    fig = plt.figure()
    18-
    for y, font, text in zip(range(5),
    19-
    ['ptmr8r', 'ptmri8r', 'ptmro8r',
    20-
    'ptmr8rn', 'ptmrr8re'],
    21-
    ['Nimbus Roman No9 L ' + x for x in
    22-
    ['', 'Italics (real italics for comparison)',
    23-
    '(slanted)', '(condensed)', '(extended)']]):
    18+
    for y, font, text in zip(
    19+
    range(5),
    20+
    ['ptmr8r', 'ptmri8r', 'ptmro8r', 'ptmr8rn', 'ptmrr8re'],
    21+
    [f'Nimbus Roman No9 L {x}'
    22+
    for x in ['', 'Italics (real italics for comparison)',
    23+
    '(slanted)', '(condensed)', '(extended)']],
    24+
    ):
    2425
    fig.text(.1, 1 - (y + 1) / 6, setfont(font) + text, usetex=True)
    2526

    2627
    fig.suptitle('Usetex font effects')

    examples/user_interfaces/toolmanager_sgskip.py

    Lines changed: 10 additions & 10 deletions
    Original file line numberDiff line numberDiff line change
    @@ -3,25 +3,26 @@
    33
    Tool Manager
    44
    ============
    55
    6-
    This example demonstrates how to:
    6+
    This example demonstrates how to
    77
    8-
    * Modify the Toolbar
    9-
    * Create tools
    10-
    * Add tools
    11-
    * Remove tools
    8+
    * modify the Toolbar
    9+
    * create tools
    10+
    * add tools
    11+
    * remove tools
    1212
    13-
    Using `matplotlib.backend_managers.ToolManager`
    13+
    using `matplotlib.backend_managers.ToolManager`.
    1414
    """
    1515

    1616
    import matplotlib.pyplot as plt
    17-
    plt.rcParams['toolbar'] = 'toolmanager'
    1817
    from matplotlib.backend_tools import ToolBase, ToolToggleBase
    1918

    2019

    20+
    plt.rcParams['toolbar'] = 'toolmanager'
    21+
    22+
    2123
    class ListTools(ToolBase):
    2224
    """List all the tools controlled by the `ToolManager`."""
    23-
    # keyboard shortcut
    24-
    default_keymap = 'm'
    25+
    default_keymap = 'm' # keyboard shortcut
    2526
    description = 'List Tools'
    2627

    2728
    def trigger(self, *args, **kwargs):
    @@ -77,7 +78,6 @@ def set_lines_visibility(self, state):
    7778
    fig.canvas.manager.toolmanager.add_tool('List', ListTools)
    7879
    fig.canvas.manager.toolmanager.add_tool('Show', GroupHideTool, gid='mygroup')
    7980

    80-
    8181
    # Add an existing tool to new group `foo`.
    8282
    # It can be added as many times as we want
    8383
    fig.canvas.manager.toolbar.add_tool('zoom', 'foo')

    examples/userdemo/anchored_box04.py

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -12,7 +12,7 @@
    1212

    1313
    fig, ax = plt.subplots(figsize=(3, 3))
    1414

    15-
    box1 = TextArea(" Test : ", textprops=dict(color="k"))
    15+
    box1 = TextArea(" Test: ", textprops=dict(color="k"))
    1616

    1717
    box2 = DrawingArea(60, 20, 0, 0)
    1818
    el1 = Ellipse((10, 10), width=16, height=5, angle=30, fc="r")

    lib/matplotlib/axes/_base.py

    Lines changed: 13 additions & 21 deletions
    Original file line numberDiff line numberDiff line change
    @@ -2878,26 +2878,23 @@ def handle_single_axis(
    28782878
    shared = shared_axes.get_siblings(self)
    28792879
    # Base autoscaling on finite data limits when there is at least one
    28802880
    # finite data limit among all the shared_axes and intervals.
    2881-
    # Also, find the minimum minpos for use in the margin calculation.
    2882-
    x_values = []
    2883-
    minimum_minpos = np.inf
    2884-
    for ax in shared:
    2885-
    x_values.extend(getattr(ax.dataLim, f"interval{name}"))
    2886-
    minimum_minpos = min(minimum_minpos,
    2887-
    getattr(ax.dataLim, f"minpos{name}"))
    2888-
    x_values = np.extract(np.isfinite(x_values), x_values)
    2889-
    if x_values.size >= 1:
    2890-
    x0, x1 = (x_values.min(), x_values.max())
    2881+
    values = [val for ax in shared
    2882+
    for val in getattr(ax.dataLim, f"interval{name}")
    2883+
    if np.isfinite(val)]
    2884+
    if values:
    2885+
    x0, x1 = (min(values), max(values))
    28912886
    elif getattr(self._viewLim, f"mutated{name}")():
    28922887
    # No data, but explicit viewLims already set:
    28932888
    # in mutatedx or mutatedy.
    28942889
    return
    28952890
    else:
    28962891
    x0, x1 = (-np.inf, np.inf)
    2897-
    # If x0 and x1 are non finite, use the locator to figure out
    2898-
    # default limits.
    2892+
    # If x0 and x1 are nonfinite, get default limits from the locator.
    28992893
    locator = axis.get_major_locator()
    29002894
    x0, x1 = locator.nonsingular(x0, x1)
    2895+
    # Find the minimum minpos for use in the margin calculation.
    2896+
    minimum_minpos = min(
    2897+
    getattr(ax.dataLim, f"minpos{name}") for ax in shared)
    29012898

    29022899
    # Prevent margin addition from crossing a sticky value. A small
    29032900
    # tolerance must be added due to floating point issues with
    @@ -4027,15 +4024,10 @@ def format_ydata(self, y):
    40274024

    40284025
    def format_coord(self, x, y):
    40294026
    """Return a format string formatting the *x*, *y* coordinates."""
    4030-
    if x is None:
    4031-
    xs = '???'
    4032-
    else:
    4033-
    xs = self.format_xdata(x)
    4034-
    if y is None:
    4035-
    ys = '???'
    4036-
    else:
    4037-
    ys = self.format_ydata(y)
    4038-
    return 'x=%s y=%s' % (xs, ys)
    4027+
    return "x={} y={}".format(
    4028+
    "???" if x is None else self.format_xdata(x),
    4029+
    "???" if y is None else self.format_ydata(y),
    4030+
    )
    40394031

    40404032
    def minorticks_on(self):
    40414033
    """

    lib/matplotlib/backends/backend_svg.py

    Lines changed: 1 addition & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -459,10 +459,7 @@ def _make_id(self, type, content):
    459459
    return '%s%s' % (type, m.hexdigest()[:10])
    460460

    461461
    def _make_flip_transform(self, transform):
    462-
    return (transform +
    463-
    Affine2D()
    464-
    .scale(1.0, -1.0)
    465-
    .translate(0.0, self.height))
    462+
    return transform + Affine2D().scale(1, -1).translate(0, self.height)
    466463

    467464
    def _get_font(self, prop):
    468465
    fname = fm.findfont(prop)

    lib/matplotlib/backends/backend_template.py

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -108,7 +108,7 @@ def points_to_pixels(self, points):
    108108

    109109
    class GraphicsContextTemplate(GraphicsContextBase):
    110110
    """
    111-
    The graphics context provides the color, line styles, etc... See the cairo
    111+
    The graphics context provides the color, line styles, etc. See the cairo
    112112
    and postscript backends for examples of mapping the graphics context
    113113
    attributes (cap styles, join styles, line widths, colors) to a particular
    114114
    backend. In cairo this is done by wrapping a cairo.Context object and
    @@ -131,7 +131,7 @@ class GraphicsContextTemplate(GraphicsContextBase):
    131131
    ########################################################################
    132132
    #
    133133
    # The following functions and classes are for pyplot and implement
    134-
    # window/figure managers, etc...
    134+
    # window/figure managers, etc.
    135135
    #
    136136
    ########################################################################
    137137

    lib/matplotlib/backends/backend_wx.py

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -299,7 +299,7 @@ def points_to_pixels(self, points):
    299299

    300300
    class GraphicsContextWx(GraphicsContextBase):
    301301
    """
    302-
    The graphics context provides the color, line styles, etc...
    302+
    The graphics context provides the color, line styles, etc.
    303303
    304304
    This class stores a reference to a wxMemoryDC, and a
    305305
    wxGraphicsContext that draws to it. Creating a wxGraphicsContext

    lib/matplotlib/collections.py

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1129,9 +1129,9 @@ def legend_elements(self, prop="colors", num="auto",
    11291129
    ix = np.argsort(xarr)
    11301130
    values = np.interp(label_values, xarr[ix], yarr[ix])
    11311131

    1132-
    kw = dict(markeredgewidth=self.get_linewidths()[0],
    1133-
    alpha=self.get_alpha())
    1134-
    kw.update(kwargs)
    1132+
    kw = {"markeredgewidth": self.get_linewidths()[0],
    1133+
    "alpha": self.get_alpha(),
    1134+
    **kwargs}
    11351135

    11361136
    for val, lab in zip(values, label_values):
    11371137
    if prop == "colors":

    lib/matplotlib/font_manager.py

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1051,7 +1051,7 @@ def json_load(filename):
    10511051
    --------
    10521052
    json_dump
    10531053
    """
    1054-
    with open(filename, 'r') as fh:
    1054+
    with open(filename) as fh:
    10551055
    return json.load(fh, object_hook=_json_decode)
    10561056

    10571057

    lib/matplotlib/legend.py

    Lines changed: 2 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -558,8 +558,7 @@ def val_or_rc(val, rc_name):
    558558
    colors.to_rgba_array(labelcolor))):
    559559
    text.set_color(color)
    560560
    else:
    561-
    raise ValueError("Invalid argument for labelcolor : %s" %
    562-
    str(labelcolor))
    561+
    raise ValueError(f"Invalid labelcolor: {labelcolor!r}")
    563562

    564563
    def _set_artist_props(self, a):
    565564
    """
    @@ -943,8 +942,7 @@ def set_bbox_to_anchor(self, bbox, transform=None):
    943942
    try:
    944943
    l = len(bbox)
    945944
    except TypeError as err:
    946-
    raise ValueError("Invalid argument for bbox : %s" %
    947-
    str(bbox)) from err
    945+
    raise ValueError(f"Invalid bbox: {bbox}") from err
    948946

    949947
    if l == 2:
    950948
    bbox = [bbox[0], bbox[1], 0, 0]

    lib/matplotlib/mpl-data/matplotlibrc

    Lines changed: 9 additions & 7 deletions
    Original file line numberDiff line numberDiff line change
    @@ -589,7 +589,7 @@
    589589
    ## ***************************************************************************
    590590
    #image.aspect: equal # {equal, auto} or a number
    591591
    #image.interpolation: antialiased # see help(imshow) for options
    592-
    #image.cmap: viridis # A colormap name, gray etc...
    592+
    #image.cmap: viridis # A colormap name (plasma, magma, etc.)
    593593
    #image.lut: 256 # the size of the colormap lookup table
    594594
    #image.origin: upper # {lower, upper}
    595595
    #image.resample: True
    @@ -679,12 +679,14 @@
    679679
    # 'tight' is incompatible with pipe-based animation
    680680
    # backends (e.g. 'ffmpeg') but will work with those
    681681
    # based on temporary files (e.g. 'ffmpeg_file')
    682-
    #savefig.pad_inches: 0.1 # Padding to be used when bbox is set to 'tight'
    683-
    #savefig.directory: ~ # default directory in savefig dialog box,
    684-
    # leave empty to always use current working directory
    685-
    #savefig.transparent: False # setting that controls whether figures are saved with a
    686-
    # transparent background by default
    687-
    #savefig.orientation: portrait # Orientation of saved figure
    682+
    #savefig.pad_inches: 0.1 # padding to be used, when bbox is set to 'tight'
    683+
    #savefig.directory: ~ # default directory in savefig dialog, gets updated after
    684+
    # interactive saves, unless set to the empty string (i.e.
    685+
    # the current directory); use '.' to start at the current
    686+
    # directory but update after interactive saves
    687+
    #savefig.transparent: False # whether figures are saved with a transparent
    688+
    # background by default
    689+
    #savefig.orientation: portrait # orientation of saved figure, for PostScript output only
    688690

    689691
    ### tk backend params
    690692
    #tk.window_focus: False # Maintain shell focus for TkAgg

    lib/matplotlib/mpl-data/stylelib/classic.mplstyle

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -329,7 +329,7 @@ figure.subplot.hspace : 0.2 # the amount of height reserved for space betwee
    329329
    ### IMAGES
    330330
    image.aspect : equal # equal | auto | a number
    331331
    image.interpolation : bilinear # see help(imshow) for options
    332-
    image.cmap : jet # gray | jet etc...
    332+
    image.cmap : jet # gray | jet | ...
    333333
    image.lut : 256 # the size of the colormap lookup table
    334334
    image.origin : upper # lower | upper
    335335
    image.resample : False

    lib/matplotlib/offsetbox.py

    Lines changed: 1 addition & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1064,8 +1064,7 @@ def set_bbox_to_anchor(self, bbox, transform=None):
    10641064
    try:
    10651065
    l = len(bbox)
    10661066
    except TypeError as err:
    1067-
    raise ValueError("Invalid argument for bbox : %s" %
    1068-
    str(bbox)) from err
    1067+
    raise ValueError(f"Invalid bbox: {bbox}") from err
    10691068

    10701069
    if l == 2:
    10711070
    bbox = [bbox[0], bbox[1], 0, 0]

    lib/matplotlib/patches.py

    Lines changed: 4 additions & 9 deletions
    Original file line numberDiff line numberDiff line change
    @@ -2181,28 +2181,23 @@ class _Style:
    21812181
    where actual styles are declared as subclass of it, and it
    21822182
    provides some helper functions.
    21832183
    """
    2184+
    21842185
    def __new__(cls, stylename, **kwargs):
    21852186
    """Return the instance of the subclass with the given style name."""
    2186-
    21872187
    # The "class" should have the _style_list attribute, which is a mapping
    21882188
    # of style names to style classes.
    2189-
    21902189
    _list = stylename.replace(" ", "").split(",")
    21912190
    _name = _list[0].lower()
    21922191
    try:
    21932192
    _cls = cls._style_list[_name]
    21942193
    except KeyError as err:
    2195-
    raise ValueError("Unknown style : %s" % stylename) from err
    2196-
    2194+
    raise ValueError(f"Unknown style: {stylename}") from err
    21972195
    try:
    21982196
    _args_pair = [cs.split("=") for cs in _list[1:]]
    21992197
    _args = {k: float(v) for k, v in _args_pair}
    22002198
    except ValueError as err:
    2201-
    raise ValueError("Incorrect style argument : %s" %
    2202-
    stylename) from err
    2203-
    _args.update(kwargs)
    2204-
    2205-
    return _cls(**_args)
    2199+
    raise ValueError(f"Incorrect style argument: {stylename}") from err
    2200+
    return _cls(**{**_args, **kwargs})
    22062201

    22072202
    @classmethod
    22082203
    def get_styles(cls):

    lib/matplotlib/projections/geo.py

    Lines changed: 2 additions & 8 deletions
    Original file line numberDiff line numberDiff line change
    @@ -156,14 +156,8 @@ def set_xlim(self, *args, **kwargs):
    156156
    def format_coord(self, lon, lat):
    157157
    """Return a format string formatting the coordinate."""
    158158
    lon, lat = np.rad2deg([lon, lat])
    159-
    if lat >= 0.0:
    160-
    ns = 'N'
    161-
    else:
    162-
    ns = 'S'
    163-
    if lon >= 0.0:
    164-
    ew = 'E'
    165-
    else:
    166-
    ew = 'W'
    159+
    ns = 'N' if lat >= 0.0 else 'S'
    160+
    ew = 'E' if lon >= 0.0 else 'W'
    167161
    return ('%f\N{DEGREE SIGN}%s, %f\N{DEGREE SIGN}%s'
    168162
    % (abs(lat), ns, abs(lon), ew))
    169163

    lib/matplotlib/text.py

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1443,7 +1443,7 @@ def _get_xy_transform(self, renderer, s):
    14431443
    elif isinstance(tr, Transform):
    14441444
    return tr
    14451445
    else:
    1446-
    raise RuntimeError("unknown return type ...")
    1446+
    raise RuntimeError("Unknown return type")
    14471447
    elif isinstance(s, Artist):
    14481448
    bbox = s.get_window_extent(renderer)
    14491449
    return BboxTransformTo(bbox)
    @@ -1452,7 +1452,7 @@ def _get_xy_transform(self, renderer, s):
    14521452
    elif isinstance(s, Transform):
    14531453
    return s
    14541454
    elif not isinstance(s, str):
    1455-
    raise RuntimeError("unknown coordinate type : %s" % s)
    1455+
    raise RuntimeError(f"Unknown coordinate type: {s!r}")
    14561456

    14571457
    if s == 'data':
    14581458
    return self.axes.transData

    0 commit comments

    Comments
     (0)
    0