2

I've got 2 text files with each two columns containing numbers like so:

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

and following python code for plotting:

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

This code generates two plots on different figures - however I'd like to have both graphs on the same figure. How can I achieve this?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Aliakbar Ahmadi
  • 366
  • 3
  • 14

1 Answers1

2

Adding newfig=False to the second plt.plotfile() set of arguments will stop the second graph being plotted in a different figure. A full example of ths can be found here.

Lenford
  • 84
  • 4
  • Thanks! How can I further achieve a legend of titles for each curve? – Aliakbar Ahmadi Aug 13 '15 at 13:23
  • You could try something along the lines of: `plt.legend()` `plt.title("Title of Plot")` `plt.xlabel("X Axis Label")` `plt.ylabel("Y Axis Label")` As per the question [here](http://stackoverflow.com/questions/11248812/matplotlib-basic-plotting-from-text-file), but I'm not too sure about that one. – Lenford Aug 13 '15 at 13:37