繁体   English   中英

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

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

我在一篇论文中看到了这张图表,需要复制它。

我怎样才能在 Python 中 plot 像这样的数字?

注意:

  • 我怀疑更大的子图可能是使用 seaborn 或使用 matplotlib 的子图绘制的
  • 较小的图指向较大图中曲线的特定部分。

在此处输入图像描述

一种策略可以使用mpl_toolkits.axes_grid1.inset_locator ,正如对这个问题的回答所建议的那样: 如何在另一个上覆盖一个 pyplot 图形

我做了一个简单的例子:

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()

这更像是一个概念证明,可以专门解决您提出的问题。 它显然需要根据您的情况进行调整和调整,以适合发布。 我希望这有帮助。

在此处输入图像描述

暂无
暂无

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

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