python – 将两个现有图合并为一个图

我还没有真正尝试过这样做,但我想知道是否有办法将两个已经存在的图合并到一个图中.任何投入将不胜感激!

最佳答案
这是一个完整的最小工作示例,它完成了提取和组合多个图中数据所需的所有步骤.

import numpy as np
import pylab as plt

# Create some test data
secret_data_X1 = np.linspace(0,1,100)
secret_data_Y1 = secret_data_X1**2
secret_data_X2 = np.linspace(1,2,100)
secret_data_Y2 = secret_data_X2**2

# Show the secret data
plt.subplot(2,1)
plt.plot(secret_data_X1,secret_data_Y1,'r')
plt.plot(secret_data_X2,secret_data_Y2,'b')

# Loop through the plots created and find the x,y values
X,Y = [],[]   
for lines in plt.gca().get_lines():
    for x,y in lines.get_xydata():
        X.append(x)
        Y.append(y)

# If you are doing a line plot,we don't kNow if the x values are
# sequential,we sort based off the x-values
idx = np.argsort(X)
X = np.array(X)[idx]
Y = np.array(Y)[idx]

plt.subplot(2,2)
plt.plot(X,Y,'g')
plt.show()

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...