如何在另一个python图形中添加不同的图形(作为插图) - python

我想制作一个像这样的图:

问题是,我已经从一些外部文件中获取了数据,并且可以制作背景图,但是我不知道如何在已有的图内添加另一个图并更改数据以得到不同的结果。他们都:

在下面,我添加了用于执行背景图的代码。
希望有人能帮忙。

from __future__ import division
import numpy as np
import matplotlib.pyplot as plt

plt.rc('text',usetex=True)
font = {'family':'serif','size':16}
plt.rc('font',**font)
plt.rc('legend',**{'fontsize':14})

matplotlib.rcParams['text.latex.preamble']=[r'\usepackage{amsmath}']

data=np.loadtxt(r'C:\...\file.txt')
plt.plot(data[:,0],data[:,6],linewidth = 3,label='B$_0$ = 1.5 T d',linestyle= '--', color='black')

plt.show()

参考方案

有多种方法可以执行此操作,具体取决于您希望插图具有的关系。

如果您只想插入与较大图形没有设置关系的图形,请执行以下操作:

import matplotlib.pyplot as plt

fig, ax1 = plt.subplots()

# These are in unitless percentages of the figure size. (0,0 is bottom left)
left, bottom, width, height = [0.25, 0.6, 0.2, 0.2]
ax2 = fig.add_axes([left, bottom, width, height])

ax1.plot(range(10), color='red')
ax2.plot(range(6)[::-1], color='green')

plt.show()

如果要在两者之间建立某种关系,请查看此处的一些示例:http://matplotlib.org/1.3.1/mpl_toolkits/axes_grid/users/overview.html#insetlocator

如果您希望将插图设为“放大”版本(例如,正好是原始比例的两倍),并且在进行交互式平移/缩放时会自动更新,则此功能很有用。

但是,对于简单的插图,只需创建一个新轴即可,如我在上面的示例中所示。

Matplotlib'粗体'字体 - python

跟随this example:import numpy as np import matplotlib.pyplot as plt fig = plt.figure() for i, label in enumerate(('A', 'B', 'C', 'D')): ax = f…

在返回'Response'(Python)中传递多个参数 - python

我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…

Python exchangelib在子文件夹中读取邮件 - python

我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…

R'relaimpo'软件包的Python端口 - python

我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。

Python ThreadPoolExecutor抑制异常 - python

from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED def div_zero(x): print('In div_zero') return x / 0 with ThreadPoolExecutor(max_workers=4) as execut…