Last active
August 28, 2018 19:56
-
-
Save bhishanpdl/101a5e0cd59e7bd9ad9c7b4f69432001 to your computer and use it in GitHub Desktop.
Plotting #plot #matplotlib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Imports | |
| from __future__ import print_function, division,with_statement | |
| import sys | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import os | |
| args = sys.argv[1] | |
| ifile, c0, c1 = args.split(' ') | |
| c0 = int(c0) | |
| c1 = int(c1) | |
| # initialize xlabel and ylabel | |
| xlabel = 'x' | |
| ylabel = 'y' | |
| # get column names | |
| with open(ifile) as fi: | |
| for line in fi.readlines(): | |
| if line.strip().startswith('#'): | |
| cols = line.split()[1:] | |
| xlabel = cols[c0] | |
| ylabel = cols[c1] | |
| break | |
| x,y = np.genfromtxt(ifile,delimiter='',usecols=(c0,c1),\ | |
| comments='#',unpack=True,dtype=None).astype(np.float64) | |
| plt.plot(x,y,'bo') | |
| plt.xlabel(xlabel) | |
| plt.ylabel(ylabel) | |
| plt.xlim(min(x)*0.9, max(x)*1.1) | |
| plt.ylim(min(y)*0.9, max(y)*1.1) | |
| plt.show() | |
| cols = [str(i) + '_' + cols[i] for i in range(len(cols))] | |
| sys.stdout.write(' '.join(cols)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment