如何在特定点绘制带有箭头的嵌套图的子图? [英] How can I plot subplots with nested plot arrowed at a specific point?

查看:45
本文介绍了如何在特定点绘制带有箭头的嵌套图的子图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

如何在Python中绘制这样的图形?

注意:

  • 我怀疑可能使用seaborn或使用matplotlib的子图绘制了较大的子图
  • 较小的图在较大图的特定位置点.

解决方案

一种解决方案可以使用 mpl_toolkits.axes_grid1.inset_locator ,如对此问题的答案所示:

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.

这篇关于如何在特定点绘制带有箭头的嵌套图的子图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆