问题
I saw this chart in a paper and need to reproduce it.
How can I plot a figure like this in Python?
Note that:
- I suspect bigger subplots are perhaps drawn using seaborn or using matplotlib's subplot
- The smaller plots are POINTING at a specific part of the curve in the bigger plots.
回答1:
One strategy can be using mpl_toolkits.axes_grid1.inset_locator
, as suggested in the answer to this question: How to overlay one pyplot figure on another
I have made a quick example:
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
import math
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
x = [n/10 for n in range(0,101)]
y = [n*n*(1-math.sin(n*10)/5) for n in x] # just create some kind of function
ax.plot(x,y) # this is the main plot
# This produces the line that points to the location.
ax.annotate("", (x[50],y[50]),
xytext=(4.0,65),
arrowprops=dict(arrowstyle="-"),)
#this is the small figure
ins_ax = inset_axes(ax, width=1.5, height=1.5,
bbox_transform=ax.transAxes, bbox_to_anchor=(0.45,0.95),)
# the small plot just by slicing the original data
ins_ax.plot(x[45:56],y[45:56])
plt.show()
This is more of a proof of concept to solve specifically the question you asked. It obviously requires tweaks and adaption to you case, to be fit for publication. I hope this helps.
来源:https://stackoverflow.com/questions/62625811/how-can-i-plot-subplots-with-nested-plot-arrowed-at-a-specific-point