相关疑难解决方法(0)

matplotlib:结合不同的数字并将它们放在一个共同的图例中

我们有一个代码,用于从input.txt文件创建数字.我们需要在一个子图中组合其中两个图.图1中的数据将绘制在左侧子图中,右侧子图中的图2将绘制,共享相同的图例,并且在轴x和y中具有相同的比例:

在此输入图像描述

这里有一些示例数据:

x  = [ 1, 2, 3, 5, 10, 100, 1000 ]
y1 = [ 1, 0.822, 0.763, 0.715, 0.680, 0.648, 0.645 ]
y2 = [ 1, 0.859, 0.812, 0.774, 0.746, 0.721, 0.718 ]

import matplotlib.pyplot as plt
# mode 01 from one case
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.plot( x, y1, label='mode 01' )
# mode 01 from other case
fig2 = plt.figure()
ax2 = fig2.add_subplot(111)
ax2.plot( x, y2, label='mode 01' )
Run Code Online (Sandbox Code Playgroud)

编辑:@nordev建议的方法有效.现在将ax1和ax2对象传递给新图非常方便,因为它们有更多的信息.似乎没有直接的方法来实现这一目标. …

python matplotlib

12
推荐指数
1
解决办法
4万
查看次数

标签 统计

matplotlib ×1

python ×1