8000 Fix polar get window extent by jklymak · Pull Request #13614 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix polar get window extent #13614

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

Merged
merged 1 commit into from
Mar 11, 2019
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
75 changes: 34 additions & 41 deletions examples/lines_bars_and_markers/markevery_demo.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -36,57 +36,53 @@
# define the figure size and grid layout properties
figsize = (10, 8)
cols = 3
gs = gridspec.GridSpec(len(cases) // cols + 1, cols)
gs.update(hspace=0.4)
rows = len(cases) // cols + 1
# define the data for cartesian plots
delta = 0.11
x = np.linspace(0, 10 - 2 * delta, 200) + delta
y = np.sin(x) + 1.0 + delta


def trim_axs(axs, N):
"""little helper to massage the axs list to have correct length..."""
axs = axs.flat
for ax in axs[N:]:
ax.remove()
return axs[:N]

###############################################################################
# Plot each markevery case for linear x and y scales

fig1 = plt.figure(num=1, figsize=figsize)
ax = []
for i, case in enumerate(cases):
row = (i // cols)
col = i % cols
ax.append(fig1.add_subplot(gs[row, col]))
ax[-1].set_title('markevery=%s' % str(case))
ax[-1].plot(x, y, 'o', ls='-', ms=4, markevery=case)
fig1, axs = plt.subplots(rows, cols, figsize=figsize, constrained_layout=True)
axs = trim_axs(axs, len(cases))
for ax, case in zip(axs, cases):
ax.set_title('markevery=%s' % str(case))
ax.plot(x, y, 'o', ls='-', ms=4, markevery=case)

###############################################################################
# Plot each markevery case for log x and y scales

fig2 = plt.figure(num=2, figsize=figsize)
axlog = []
for i, case in enumerate(cases):
row = (i // cols)
col = i % cols
axlog.append(fig2.add_subplot(gs[row, col]))
axlog[-1].set_title('markevery=%s' % str(case))
axlog[-1].set_xscale('log')
axlog[-1].set_yscale('log')
axlog[-1].plot(x, y, 'o', ls='-', ms=4, markevery=case)
fig2.tight_layout()
fig2, axs = plt.subplots(rows, cols, figsize=figsize, constrained_layout=True)
axs = trim_axs(axs, len(cases))
for ax, case in zip(axs, cases):
ax.set_title('markevery=%s' % str(case))
ax.set_xscale('log')
ax.set_yscale('log')
ax.plot(x, y, 'o', ls='-', ms=4, markevery=case)

###############################################################################
# Plot each markevery case for linear x and y scales but zoomed in
# note the behaviour when zoomed in. When a start marker offset is specified
# it is always interpreted with respect to the first data point which might be
# different to the first visible data point.

fig3 = plt.figure(num=3, figsize=figsize)
axzoom = []
for i, case in enumerate(cases):
row = (i // cols)
col = i % cols
axzoom.append(fig3.add_subplot(gs[row, col]))
axzoom[-1].set_title('markevery=%s' % str(case))
axzoom[-1].plot(x, y, 'o', ls='-', ms=4, markevery=case)
axzoom[-1].set_xlim((6, 6.7))
axzoom[-1].set_ylim((1.1, 1.7))
fig3.tight_layout()
fig3, axs = plt.subplots(rows, cols, figsize=figsize, constrained_layout=True)
axs = trim_axs(axs, len(cases))
for ax, case in zip(axs, cases):
ax.set_title('markevery=%s' % str(case))
ax.plot(x, y, 'o', ls='-', ms=4, markevery=case)
ax.set_xlim((6, 6.7))
ax.set_ylim((1.1, 1.7))

# define data for polar plots
r = np.linspace(0, 3.0, 200)
Expand All @@ -95,14 +91,11 @@
###############################################################################
# Plot each markevery case for polar plots

fig4 = plt.figure(num=4, figsize=figsize)
axpolar = []
for i, case in enumerate(cases):
row = (i // cols)
col = i % cols
axpolar.append(fig4.add_subplot(gs[row, col], projection='polar'))
axpolar[-1].set_title('markevery=%s' % str(case))
axpolar[-1].plot(theta, r, 'o', ls='-', ms=4, markevery=case)
fig4.tight_layout()
fig4, axs = plt.subplots(rows, cols, figsize=figsize,
subplot_kw={'projection': 'polar'}, constrained_layout=True)
axs = trim_axs(axs, len(cases))
for ax, case in zip(axs, cases):
ax.set_title('markevery=%s' % str(case))
ax.plot(theta, r, 'o', ls='-', ms=4, markevery=case)

plt.show()
2 changes: 2 additions & 0 deletions lib/matplotlib/spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def get_window_extent(self, renderer=None):
# correct:
self._adjust_location()
bb = super().get_window_extent(renderer=renderer)
if self.axis is None:
return bb
bboxes = [bb]
tickstocheck = [self.axis.majorTicks[0]]
if len(self.axis.minorTicks) > 1:
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6271,6 +6271,14 @@ def test_minor_accountedfor():
atol=1e-2)


def test_get_tightbbox_polar():
fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
fig.canvas.draw()
bb = ax.get_tightbbox(fig.canvas.get_renderer())
assert_allclose(bb.extents,
[107.7778, 29.2778, 539.7847, 450.7222], rtol=1e-03)


@check_figures_equal(extensions=["png"])
def test_axis_bool_arguments(fig_test, fig_ref):
# Test if False and "off" give the same
Expand Down
0