Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ignore =
# Normal default
E121,E123,E126,E226,E24,E704,W503,W504,
# Additional ignores:
E122, E125, E127, E128, E129, E131,
E122, E125, E127, E129, E131,
E265, E266,
E305, E306,
E722, E741,
Expand Down
17 changes: 9 additions & 8 deletions doc/sphinxext/missing_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def _record_reference(self, record):
self.app.env.missing_references_warnings = defaultdict(set)

record_missing_reference(self.app,
self.app.env.missing_references_warnings,
record.location)
self.app.env.missing_references_warnings,
record.location)

def filter(self, record):
self._record_reference(record)
Expand Down Expand Up @@ -157,13 +157,14 @@ def _warn_unused_missing_references(app):
return

# This is a dictionary of {(domain_type, target): locations}
references_ignored = getattr(app.env,
'missing_references_ignored_references', {})
references_ignored = getattr(
app.env, 'missing_references_ignored_references', {})
references_events = getattr(app.env, 'missing_references_events', {})

# Warn about any reference which is no longer missing.
for (domain_type, target), locations in references_ignored.items():
missing_reference_locations = [_truncate_location(location)
missing_reference_locations = [
_truncate_location(location)
for location in references_events.get((domain_type, target), [])]

# For each ignored reference location, ensure a missing reference
Expand All @@ -176,9 +177,9 @@ def _warn_unused_missing_references(app):
f" from {app.config.missing_references_filename}."
"It is no longer a missing reference in the docs.")
logger.warning(msg,
location=ignored_reference_location,
type='ref',
subtype=domain_type)
location=ignored_reference_location,
type='ref',
subtype=domain_type)


def save_missing_references_handler(app, exc):
Expand Down
4 changes: 2 additions & 2 deletions examples/color/custom_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@
# in the middle of the range.
cdict4 = {**cdict3,
'alpha': ((0.0, 1.0, 1.0),
# (0.25, 1.0, 1.0),
# (0.25, 1.0, 1.0),
(0.5, 0.3, 0.3),
# (0.75, 1.0, 1.0),
# (0.75, 1.0, 1.0),
(1.0, 1.0, 1.0)),
}

Expand Down
4 changes: 2 additions & 2 deletions examples/images_contours_and_fields/contour_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
axs = _axs.flatten()

cset1 = axs[0].contourf(X, Y, Z, levels, norm=norm,
cmap=cm.get_cmap(cmap, len(levels) - 1))
cmap=cm.get_cmap(cmap, len(levels) - 1))
# It is not necessary, but for the colormap, we need only the
# number of levels minus 1. To avoid discretization error, use
# either this number or a large number such as the default (256).
Expand Down Expand Up @@ -84,7 +84,7 @@
# image pixel (each color block on the following subplot), so the
# domain that is contoured does not extend beyond these pixel centers.
im = axs[3].imshow(Z, interpolation='nearest', extent=extent,
cmap=cmap, norm=norm)
cmap=cmap, norm=norm)
axs[3].contour(Z, levels, colors='k', origin='image', extent=extent)
ylim = axs[3].get_ylim()
axs[3].set_ylim(ylim[::-1])
Expand Down
2 changes: 1 addition & 1 deletion examples/images_contours_and_fields/plot_streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

ax3 = fig.add_subplot(gs[1, 1])
strm = ax3.streamplot(X, Y, U, V, color=U, linewidth=2,
cmap='autumn', start_points=seed_points.T)
cmap='autumn', start_points=seed_points.T)
fig.colorbar(strm.lines)
ax3.set_title('Controlling Starting Points')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def experiment_res(x, y):

fig, ax = plt.subplots()
ax.set_aspect('equal')
ax.set_title("Filtering a Delaunay mesh\n" +
"(application to high-resolution tricontouring)")
ax.set_title("Filtering a Delaunay mesh\n"
"(application to high-resolution tricontouring)")

# 1) plot of the refined (computed) data contours:
ax.tricontour(tri_refi, z_test_refi, levels=levels, cmap=cmap,
Expand Down
10 changes: 5 additions & 5 deletions examples/lines_bars_and_markers/markevery_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def trim_axs(axs, N):
###############################################################################
# Plot each markevery case for linear x and y scales

fig1, axs = plt.subplots(rows, cols, figsize=figsize, constrained_layout=True)
axs = plt.figure(figsize=figsize, constrained_layout=True).subplots(rows, cols)
axs = trim_axs(axs, len(cases))
for ax, case in zip(axs, cases):
ax.set_title('markevery=%s' % str(case))
Expand All @@ -62,7 +62,7 @@ def trim_axs(axs, N):
###############################################################################
# Plot each markevery case for log x and y scales

fig2, axs = plt.subplots(rows, cols, figsize=figsize, constrained_layout=True)
axs = plt.figure(figsize=figsize, constrained_layout=True).subplots(rows, cols)
axs = trim_axs(axs, len(cases))
for ax, case in zip(axs, cases):
ax.set_title('markevery=%s' % str(case))
Expand All @@ -76,7 +76,7 @@ def trim_axs(axs, N):
# it is always interpreted with respect to the first data point which might be
# different to the first visible data point.

fig3, axs = plt.subplots(rows, cols, figsize=figsize, constrained_layout=True)
axs = plt.figure(figsize=figsize, constrained_layout=True).subplots(rows, cols)
axs = trim_axs(axs, len(cases))
for ax, case in zip(axs, cases):
ax.set_title('markevery=%s' % str(case))
Expand All @@ -91,8 +91,8 @@ def trim_axs(axs, N):
###############################################################################
# Plot each markevery case for polar plots

fig4, axs = plt.subplots(rows, cols, figsize=figsize,
subplot_kw={'projection': 'polar'}, constrained_layout=True)
axs = plt.figure(figsize=figsize, constrained_layout=True).subplots(
rows, cols, subplot_kw={'projection': 'polar'})
axs = trim_axs(axs, len(cases))
for ax, case in zip(axs, cases):
ax.set_title('markevery=%s' % str(case))
Expand Down
9 changes: 5 additions & 4 deletions examples/statistics/barchart_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ def plot_student_results(student, scores, cohort_size):

# Center the text vertically in the bar
yloc = rect.get_y() + rect.get_height() / 2
label = ax1.annotate(rank_str, xy=(width, yloc), xytext=(xloc, 0),
textcoords="offset points",
ha=align, va='center',
color=clr, weight='bold', clip_on=True)
label = ax1.annotate(
rank_str, xy=(width, yloc), xytext=(xloc, 0),
textcoords="offset points",
horizontalalignment=align, verticalalignment='center',
color=clr, weight='bold', clip_on=True)
rect_labels.append(label)

# make the interactive mouse over give the bar title
Expand Down
15 changes: 6 additions & 9 deletions examples/statistics/confidence_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,8 @@ def confidence_ellipse(x, y, ax, n_std=3.0, facecolor='none', **kwargs):
# two-dimensionl dataset.
ell_radius_x = np.sqrt(1 + pearson)
ell_radius_y = np.sqrt(1 - pearson)
ellipse = Ellipse((0, 0),
width=ell_radius_x * 2,
height=ell_radius_y * 2,
facecolor=facecolor,
**kwargs)
ellipse = Ellipse((0, 0), width=ell_radius_x * 2, height=ell_radius_y * 2,
facecolor=facecolor, **kwargs)

# Calculating the stdandard deviation of x from
# the squareroot of the variance and multiplying
Expand Down Expand Up @@ -176,11 +173,11 @@ def get_correlated_dataset(n, dependency, mu, scale):
ax_nstd.scatter(x, y, s=0.5)

confidence_ellipse(x, y, ax_nstd, n_std=1,
label=r'$1\sigma$', edgecolor='firebrick')
label=r'$1\sigma$', edgecolor='firebrick')
confidence_ellipse(x, y, ax_nstd, n_std=2,
label=r'$2\sigma$', edgecolor='fuchsia', linestyle='--')
label=r'$2\sigma$', edgecolor='fuchsia', linestyle='--')
confidence_ellipse(x, y, ax_nstd, n_std=3,
label=r'$3\sigma$', edgecolor='blue', linestyle=':')
label=r'$3\sigma$', edgecolor='blue', linestyle=':')

ax_nstd.scatter(mu[0], mu[1], c='red', s=3)
ax_nstd.set_title('Different standard deviations')
Expand Down Expand Up @@ -209,7 +206,7 @@ def get_correlated_dataset(n, dependency, mu, scale):
# Plot the ellipse with zorder=0 in order to demonstrate
# its transparency (caused by the use of alpha).
confidence_ellipse(x, y, ax_kwargs,
alpha=0.5, facecolor='pink', edgecolor='purple', zorder=0)
alpha=0.5, facecolor='pink', edgecolor='purple', zorder=0)

ax_kwargs.scatter(x, y, s=0.5)
ax_kwargs.scatter(mu[0], mu[1], c='red', s=3)
Expand Down
6 changes: 3 additions & 3 deletions examples/subplots_axes_and_figures/axes_box_aspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
# figure.

fig5, axs = plt.subplots(2, 2, sharex="col", sharey="row",
gridspec_kw=dict(height_ratios=[1, 3],
width_ratios=[3, 1]))
gridspec_kw=dict(height_ratios=[1, 3],
width_ratios=[3, 1]))
axs[0, 1].set_visible(False)
axs[0, 0].set_box_aspect(1/3)
axs[1, 0].set_box_aspect(1)
Expand Down Expand Up @@ -138,7 +138,7 @@
# following creates a 2 by 3 subplot grid with all square axes.

fig7, axs = plt.subplots(2, 3, subplot_kw=dict(box_aspect=1),
sharex=True, sharey=True, constrained_layout=True)
sharex=True, sharey=True, constrained_layout=True)

for i, ax in enumerate(axs.flat):
ax.scatter(i % 3, -((i // 3) - 0.5)*200, c=[plt.cm.hsv(i / 6)], s=300)
Expand Down
5 changes: 2 additions & 3 deletions examples/ticks_and_spines/date_concise_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@
'%d %b %Y',
'%d %b %Y %H:%M', ]

converter = mdates.ConciseDateConverter(formats=formats,
zero_formats=zero_formats,
offset_formats=offset_formats)
converter = mdates.ConciseDateConverter(
formats=formats, zero_formats=zero_formats, offset_formats=offset_formats)

munits.registry[np.datetime64] = converter
munits.registry[datetime.date] = converter
Expand Down
8 changes: 4 additions & 4 deletions examples/userdemo/colormap_normalizations_diverging.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
colors_undersea = plt.cm.terrain(np.linspace(0, 0.17, 256))
colors_land = plt.cm.terrain(np.linspace(0.25, 1, 256))
all_colors = np.vstack((colors_undersea, colors_land))
terrain_map = colors.LinearSegmentedColormap.from_list('terrain_map',
all_colors)
terrain_map = colors.LinearSegmentedColormap.from_list(
'terrain_map', all_colors)

# make the norm: Note the center is offset so that the land has more
# dynamic range:
divnorm = colors.TwoSlopeNorm(vmin=-500, vcenter=0, vmax=4000)

pcm = ax.pcolormesh(longitude, latitude, topo, rasterized=True, norm=divnorm,
cmap=terrain_map,)
pcm = ax.pcolormesh(
longitude, latitude, topo, rasterized=True, norm=divnorm, cmap=terrain_map)
ax.set_xlabel('Lon $[^o E]$')
ax.set_ylabel('Lat $[^o N]$')
ax.set_aspect(1 / np.cos(np.deg2rad(49)))
Expand Down
4 changes: 2 additions & 2 deletions examples/userdemo/demo_gridspec06.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def squiggle_xy(a, b, c, d):
outer_grid = gridspec.GridSpec(4, 4, wspace=0.0, hspace=0.0)

for i in range(16):
inner_grid = gridspec.GridSpecFromSubplotSpec(3, 3,
subplot_spec=outer_grid[i], wspace=0.0, hspace=0.0)
inner_grid = gridspec.GridSpecFromSubplotSpec(
3, 3, subplot_spec=outer_grid[i], wspace=0.0, hspace=0.0)
a = i // 4 + 1
b = i % 4 + 1
for j, (c, d) in enumerate(product(range(1, 4), repeat=2)):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/_cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ def _gist_yarg(x): return 1 - x
# See `A Color Map for Effective Black-and-White Rendering of Color-Scale
# Images' by Carey Rappaport
# http://www.mathworks.com/matlabcentral/fileexchange/2662-cmrmap-m
_CMRmap_data = {'red': ((0.000, 0.00, 0.00),
_CMRmap_data = {'red': ((0.000, 0.00, 0.00),
(0.125, 0.15, 0.15),
(0.250, 0.30, 0.30),
(0.375, 0.60, 0.60),
Expand Down
14 changes: 7 additions & 7 deletions lib/matplotlib/_constrained_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _axes_all_finite_sized(fig):

######################################################
def do_constrained_layout(fig, renderer, h_pad, w_pad,
hspace=None, wspace=None):
hspace=None, wspace=None):
"""
Do the constrained_layout. Called at draw time in
``figure.constrained_layout()``
Expand Down Expand Up @@ -420,7 +420,7 @@ def _align_spines(fig, gs):
axc._poslayoutbox.height * height0 / heightC)
alignheight = True
elif _in_same_column(colnum0min, colnum0max,
colnumCmin, colnumCmax):
colnumCmin, colnumCmax):
if height0 > heightC:
ax._poslayoutbox.constrain_height_min(
axc._poslayoutbox.height * height0 / heightC)
Expand All @@ -441,7 +441,7 @@ def _align_spines(fig, gs):
axc._poslayoutbox.width * width0 / widthC)
alignwidth = True
elif _in_same_row(rownum0min, rownum0max,
rownumCmin, rownumCmax):
rownumCmin, rownumCmax):
if width0 > widthC:
ax._poslayoutbox.constrain_width_min(
axc._poslayoutbox.width * width0 / widthC)
Expand Down Expand Up @@ -482,10 +482,10 @@ def _arrange_subplotspecs(gs, hspace=0, wspace=0):
thepad = wspace / ncols
if colNum0max < colNumCmin:
layoutbox.hstack([ss0._layoutbox, ssc._layoutbox],
padding=thepad)
padding=thepad)
if colNumCmax < colNum0min:
layoutbox.hstack([ssc._layoutbox, ss0._layoutbox],
padding=thepad)
padding=thepad)

####
# vertical alignment
Expand Down Expand Up @@ -621,7 +621,7 @@ def layoutcolorbargridspec(parents, cax, shrink, aspect, location, pad=0.05):
else:
order = [lb, ax._layoutbox]
layoutbox.hstack(order, padding=pad * gslb.width,
strength='strong')
strength='strong')
# constrain the height and center...
# This isn't quite right. We'd like the colorbar
# pos to line up w/ the axes poss, not the size of the
Expand Down Expand Up @@ -681,7 +681,7 @@ def layoutcolorbargridspec(parents, cax, shrink, aspect, location, pad=0.05):
else:
order = [lb, ax._layoutbox]
layoutbox.vstack(order, padding=pad * gslb.width,
strength='strong')
strength='strong')

# Vertical Layout: need to check all the axes in this gridspec
for ch in gslb.children:
Expand Down
9 changes: 5 additions & 4 deletions lib/matplotlib/_layoutbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,11 @@ def layout_from_subplotspec(self, subspec,
return lb

def __repr__(self):
args = (self.name, self.left.value(), self.bottom.value(),
self.right.value(), self.top.value())
return ('LayoutBox: %25s, (left: %1.3f) (bot: %1.3f) '
'(right: %1.3f) (top: %1.3f) ') % args
return (f'LayoutBox: {self.name:25s}, '
f'(left: {self.left.value():1.3f}) '
f'(bot: {self.bottom.value():1.3f}) '
f'(right: {self.right.value():1.3f}) '
f'(top: {self.top.value():1.3f})')


# Utility functions that act on layoutboxes...
Expand Down
Loading