Last active
October 11, 2016 14:52
-
-
Save Zulko/c8d01add577cc71cf09a523aa51c1448 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mpl_toolkits.axes_grid.inset_locator import inset_axes | |
def place_inset_ax_in_data_coordinates(ax, bbox): | |
"""Return an ax inset in the given ax at the given bbox in | |
data coordinates (bottom, left, width, height)""" | |
bottom, left, width, height = bbox | |
pixels_data_00 = ax.transData.transform([0,0]) | |
pixels_data_11 = ax.transData.transform([1,1]) | |
iwidth, iheight = (pixels_data_11 - pixels_data_00) / ax.figure.dpi | |
return inset_locator.inset_axes( | |
ax, iwidth, iheight, | |
loc=10, # means "center" | |
bbox_to_anchor=[bottom, left, width, height], | |
bbox_transform= ax.transData | |
) | |
def draw_curve_on_ax(ax): | |
#ax.axis("off") | |
ax.plot([0,1,2,3],[0,3,1,2],c="k") | |
import matplotlib.pyplot as plt | |
fig, ax = plt.subplots(1, figsize=(6,6)) | |
draw_curve_on_ax(ax) | |
axc = place_inset_ax_in_data_coordinates(ax, [0.5, 0.5,1,1]) | |
draw_curve_on_ax(axc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment