python把图像放入图表中_如何在另一个python图表中添加不同的图形(作为插图)...

I'd like to make a graph like that:

the problem is, I've got the data from some external files, and I can make the background graph, but I have no idea how to add another graph inside of the one that I already have and change the data to have different results in both of them:

Below I am adding the code I am using to do the background graph.

Hope someone can help.

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

解决方案

There's more than one way do to this, depending on the relationship that you want the inset to have.

If you just want to inset a graph that has no set relationship with the bigger graph, just do something like:

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

If you want to have some sort of relationship between the two, have a look at some of the examples here: http://matplotlib.org/1.3.1/mpl_toolkits/axes_grid/users/overview.html#insetlocator

This is useful if you want the inset to be a "zoomed in" version, (say, at exactly twice the scale of the original) that will automatically update as you pan/zoom interactively.

For simple insets, though, just create a new axes as I showed in the example above.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值