【问题标题】:matplotlib.pyplot.plotfile() - How to plot multiple graphs into same figure?matplotlib.pyplot.plotfile() - 如何将多个图形绘制成同一个图形?
【发布时间】:2015-08-13 12:41:11
【问题描述】:

我有 2 个文本文件,每两列包含如下数字:

26 0.000342231
27 0.000342231
28 0.000684463
29 0.00136893
30 0.00102669
31 0.00308008
32 0.00308008
33 0.00444901
...
77 0.00102669
79 0.000684463
80 0.000342231
81 0.000342231
82 0.000684463

以及以下用于绘图的python代码:

import numpy as np
import matplotlib.pyplot as plt
import scipy, scipy.stats

plt.plotfile('histdata1.txt', delimiter=' ', cols=(0, 1), names=('stale block', 'frequency'), marker='o', markersize=5, c='r', alpha=0.5, linewidth=0, markeredgewidth=0, markeredgecolor='w')
plt.plotfile('histdata3.txt', delimiter=' ', cols=(0, 1), names=('stale block', 'frequency'), marker='o', markersize=5, c='g', alpha=0.5, linewidth=0, markeredgewidth=0, markeredgecolor='w')

plt.show()

此代码在不同的图形上生成两个图 - 但是我希望将两个图形都放在同一个图形上。我怎样才能做到这一点?

【问题讨论】:

    标签: python matplotlib plot histogram


    【解决方案1】:

    newfig=False 添加到第二个plt.plotfile() 参数集将停止以不同的图形绘制第二个图形。完整的例子可以在here.

    【讨论】:

    • 谢谢!如何进一步实现每条曲线的标题图例?
    • 您可以尝试以下方式:plt.legend()plt.title("Title of Plot")plt.xlabel("X Axis Label")plt.ylabel("Y Axis Label") 根据问题here,但我不太确定那个。跨度>
    猜你喜欢
    • 2021-04-01
    • 2023-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-23
    • 1970-01-01
    • 1970-01-01
    • 2020-01-04
    相关资源
    最近更新 更多