InĀ [1]:
# Code attribution: Yiyin Shen, Tyler Caraza-Harter
import matplotlib.pyplot as plt
InĀ [2]:
# Past exam question
fig, ax = plt.subplots()
ax.set_xlim(0, 0.8)
ax.set_ylim(0, 1)
f = plt.Circle((0.4, 0.5), 0.3, transform = fig.transFigure, color = "red", alpha = 0.5)
x = plt.Circle((0.4, 0.5), 0.3, transform = ax.transAxes, color = "green", alpha = 0.5)
d = plt.Circle((0.4, 0.5), 0.3, transform = ax.transData, color = "blue", alpha = 0.5)
fig.add_artist(f)
ax.add_artist(x)
ax.add_artist(d)
Out[2]:
<matplotlib.patches.Circle at 0x2462b2f6fd0>
InĀ [3]:
# Quiz question
fig, ax = plt.subplots()
ax.set_xlim(0, 2)
ax.set_ylim(0, 2)
f = plt.Circle((0.5, 0.5), 0.5, transform = fig.transFigure, color = "red", alpha = 0.5)
x = plt.Circle((0.5, 0.5), 0.5, transform = ax.transAxes, color = "green", alpha = 0.5)
d = plt.Circle((0.5, 0.5), 0.5, transform = ax.transData, color = "blue", alpha = 0.5)
fig.add_artist(f)
ax.add_artist(x)
ax.add_artist(d)
Out[3]:
<matplotlib.patches.Circle at 0x2462b40f990>
InĀ [4]:
# Lecture example, matplotlib does clipping
fig, ax = plt.subplots()
ax.set_xlim(0, 0.5)
ax.set_ylim(0, 0.5)
f = plt.Circle((0.5, 0.5), 0.5, transform = fig.transFigure, color = "red", alpha = 0.5)
x = plt.Circle((0.5, 0.5), 0.5, transform = ax.transAxes, color = "green", alpha = 0.5)
d = plt.Circle((0.5, 0.5), 0.5, transform = ax.transData, color = "blue", alpha = 0.5)
fig.add_artist(f)
ax.add_artist(x)
ax.add_artist(d)
Out[4]:
<matplotlib.patches.Circle at 0x2462b4465d0>
InĀ [5]:
# Example where TransData is the largest
fig, ax = plt.subplots()
ax.set_xlim(0.4, 0.6)
ax.set_ylim(0.4, 0.6)
f = plt.Circle((0.5, 0.5), 0.1, transform = fig.transFigure, color = "red", alpha = 0.5)
x = plt.Circle((0.5, 0.5), 0.1, transform = ax.transAxes, color = "green", alpha = 0.5)
d = plt.Circle((0.5, 0.5), 0.1, transform = ax.transData, color = "blue", alpha = 0.5)
fig.add_artist(f)
ax.add_artist(x)
ax.add_artist(d)
Out[5]:
<matplotlib.patches.Circle at 0x2462e5f0690>