Created
June 12, 2019 23:55
-
-
Save nicoguaro/63a227f52d85eb0a319ff0b214c9e9c1 to your computer and use it in GitHub Desktop.
Plot with an inset and a background color for the inset
This file contains hidden or 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
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.patches as patches | |
x = np.linspace(0, 1, 100) | |
y = np.sin(4*np.pi*x) | |
# Big plot | |
ax = plt.subplot(111) | |
plt.plot(x, y, "k", zorder=3, alpha=0.4) | |
plt.xlabel("x") | |
plt.ylabel("y") | |
plt.ylim(-1, 5) | |
plt.grid() | |
# Rectangle | |
rec = patches.Rectangle((0, 1), 0.8, 4, zorder=4, facecolor="#eeeeee") | |
ax.add_patch(rec) | |
# Small plot | |
ax2 = plt.axes([.25, .5, .4, .32], zorder=5) | |
plt.plot(x, y, "k", zorder=3, alpha=0.4) | |
plt.xlabel("x", fontsize=10) | |
plt.ylabel("y", fontsize=10) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment