Skip to content

Instantly share code, notes, and snippets.

@ExcaliburZero
Last active November 25, 2016 18:32
Show Gist options
  • Save ExcaliburZero/92fc6c2c09353eca287b71127ea4bdfa to your computer and use it in GitHub Desktop.
Save ExcaliburZero/92fc6c2c09353eca287b71127ea4bdfa to your computer and use it in GitHub Desktop.
A Python script for graphing RR Lyrae data.
import sys
import matplotlib.pyplot as plt
def main():
if not len(sys.argv) == 3:
print("Invalid number of arguments.")
print("python graph_rr_lyrae.py INPUTFILE OUTPUTFILE")
sys.exit(1)
else:
input_file = sys.argv[1]
output_file = sys.argv[2]
(times, light_values) = parse_data_file(input_file)
create_graph(times, light_values, output_file)
print("Successfully saved graph to {0}".format(output_file))
def parse_data_file(input_file):
lines = [line.rstrip('\n').split(" ") for line in open(input_file)]
# Parse in the input data
times = [line[0] for line in lines]
light_values = [line[1] for line in lines]
return times, light_values
def create_graph(times, light_values, output_file):
# Create the graph
plt.plot(times, light_values, label='input data')
plt.xlabel('time')
plt.ylabel('light')
# Save the graph to the output file
plt.savefig(output_file)
# Run the main method of the script
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment