简体   繁体   中英

How can I plot subplots with nested plot arrowed at a specific point?

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.

在此处输入图像描述

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.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM