-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Use subplots() instead of axes_grid in suitable examples. #10127
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,61 +8,38 @@ | |
import matplotlib.pyplot as plt | ||
import matplotlib.patches as mpatches | ||
|
||
|
||
fig, axs = plt.subplots(2, 4) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I don't mind it, but this one is pretty different from the old version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous example had a bunch of empty, useless subplots. |
||
x1, y1 = 0.3, 0.3 | ||
x2, y2 = 0.7, 0.7 | ||
|
||
fig = plt.figure(1) | ||
fig.clf() | ||
from mpl_toolkits.axes_grid1.axes_grid import Grid | ||
from matplotlib.offsetbox import AnchoredText | ||
|
||
from matplotlib.font_manager import FontProperties | ||
|
||
|
||
def add_at(ax, t, loc=2): | ||
fp = dict(size=10) | ||
_at = AnchoredText(t, loc=loc, prop=fp) | ||
ax.add_artist(_at) | ||
return _at | ||
|
||
|
||
grid = Grid(fig, 111, (4, 4), label_mode="1", share_all=True) | ||
|
||
grid[0].set_autoscale_on(False) | ||
|
||
ax = grid[0] | ||
ax = axs.flat[0] | ||
ax.plot([x1, x2], [y1, y2], "o") | ||
ax.annotate("", | ||
xy=(x1, y1), xycoords='data', | ||
xytext=(x2, y2), textcoords='data', | ||
arrowprops=dict(arrowstyle="->")) | ||
ax.text(.05, .95, "A $->$ B", transform=ax.transAxes, ha="left", va="top") | ||
|
||
add_at(ax, "A $->$ B", loc=2) | ||
|
||
|
||
ax = grid[1] | ||
ax = axs.flat[2] | ||
ax.plot([x1, x2], [y1, y2], "o") | ||
ax.annotate("", | ||
xy=(x1, y1), xycoords='data', | ||
xytext=(x2, y2), textcoords='data', | ||
arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0.3")) | ||
|
||
add_at(ax, "connectionstyle=arc3", loc=2) | ||
|
||
arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0.3", | ||
shrinkB=5) | ||
) | ||
ax.text(.05, .95, "shrinkB=5", transform=ax.transAxes, ha="left", va="top") | ||
|
||
ax = grid[2] | ||
ax = axs.flat[3] | ||
ax.plot([x1, x2], [y1, y2], "o") | ||
ax.annotate("", | ||
xy=(x1, y1), xycoords='data', | ||
xytext=(x2, y2), textcoords='data', | ||
arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0.3", | ||
shrinkB=5) | ||
) | ||
|
||
add_at(ax, "shrinkB=5", loc=2) | ||
|
||
arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0.3")) | ||
ax.text(.05, .95, "connectionstyle=arc3", transform=ax.transAxes, ha="left", va="top") | ||
|
||
ax = grid[3] | ||
ax = axs.flat[4] | ||
ax.plot([x1, x2], [y1, y2], "o") | ||
el = mpatches.Ellipse((x1, y1), 0.3, 0.4, angle=30, alpha=0.5) | ||
ax.add_artist(el) | ||
|
@@ -72,8 +49,7 @@ def add_at(ax, t, loc=2): | |
arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0.2") | ||
) | ||
|
||
|
||
ax = grid[4] | ||
ax = axs.flat[5] | ||
ax.plot([x1, x2], [y1, y2], "o") | ||
el = mpatches.Ellipse((x1, y1), 0.3, 0.4, angle=30, alpha=0.5) | ||
ax.add_artist(el) | ||
|
@@ -83,11 +59,9 @@ def add_at(ax, t, loc=2): | |
arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=0.2", | ||
patchB=el) | ||
) | ||
ax.text(.05, .95, "patchB", transform=ax.transAxes, ha="left", va="top") | ||
|
||
add_at(ax, "patchB", loc=2) | ||
|
||
|
||
ax = grid[5] | ||
ax = axs.flat[6] | ||
ax.plot([x1], [y1], "o") | ||
ax.annotate("Test", | ||
xy=(x1, y1), xycoords='data', | ||
|
@@ -96,11 +70,9 @@ def add_at(ax, t, loc=2): | |
bbox=dict(boxstyle="round", fc="w"), | ||
arrowprops=dict(arrowstyle="->") | ||
) | ||
ax.text(.05, .95, "annotate", transform=ax.transAxes, ha="left", va="top") | ||
|
||
add_at(ax, "annotate", loc=2) | ||
|
||
|
||
ax = grid[6] | ||
ax = axs.flat[7] | ||
ax.plot([x1], [y1], "o") | ||
ax.annotate("Test", | ||
xy=(x1, y1), xycoords='data', | ||
|
@@ -109,7 +81,9 @@ def add_at(ax, t, loc=2): | |
bbox=dict(boxstyle="round", fc="w", ), | ||
arrowprops=dict(arrowstyle="->", relpos=(0., 0.)) | ||
) | ||
ax.text(.05, .95, "relpos=(0,0)", transform=ax.transAxes, ha="left", va="top") | ||
|
||
add_at(ax, "relpos=(0,0)", loc=2) | ||
for ax in axs.flat: | ||
ax.set(xlim=(0, 1), ylim=(0, 1), xticks=[], yticks=[], aspect=1) | ||
|
||
plt.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you change the shape on purpose? I don't really mind, but the original was 1x4...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you'd need to set a figsize (otherwise the subplots are really small), and it just works as well without it after reshaping to (2, 2). Basically, trying to concentrate the example on the relevant points.
(the connectionstyle example does set the figsize because I don't think it can really be made to work nicely without it).