Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import matplotlib.pyplot as plt
def main():
resized = (8, 3)
basic_example()
basic_example(resized)
fixed_aspect()
fixed_aspect(resized)
fixed_aspect_datalim()
fixed_aspect_datalim(resized)
plt.show()
def basic_example(figsize=None):
fig, ax = plt.subplots(figsize=figsize)
circ = plt.Circle((5, 10), 3, facecolor='lightblue')
ax.add_patch(circ)
ax.margins(0.05)
show_bounds(ax)
return ax
def fixed_aspect(figsize=None):
ax = basic_example(figsize)
ax.set(xlim=[0, 10], ylim=[0, 20], aspect=1)
return ax
def fixed_aspect_datalim(figsize=None):
fixed_aspect(figsize).set(adjustable='datalim')
def show_bounds(ax):
axes_box = ax.get_position().bounds
# Maximum Axes size
fig_box(ax, axes_box, lw=5, ec='mediumseagreen', zorder=10)
# Figure outline
fig_box(ax, (0.01, 0.02, 0.98, 0.96), lw=4, ec='salmon')
def fig_box(ax, bounds, **kwargs):
left, bottom, width, height = bounds
rect = plt.Rectangle((left, bottom), width, height, **kwargs)
rect.set(clip_on=False, facecolor='none', transform=ax.figure.transFigure)
ax.add_artist(rect)
return rect
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.