简体   繁体   English

如何在 plot 子图中嵌套 plot 箭头指向特定点?

[英]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?我怎样才能在 Python 中 plot 像这样的数字?

Note that:注意:

  • I suspect bigger subplots are perhaps drawn using seaborn or using matplotlib's subplot我怀疑更大的子图可能是使用 seaborn 或使用 matplotlib 的子图绘制的
  • 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一种策略可以使用mpl_toolkits.axes_grid1.inset_locator ,正如对这个问题的回答所建议的那样: 如何在另一个上覆盖一个 pyplot 图形

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.我希望这有帮助。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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