I am trying to read some data from a file and then take the first row and plot it on a graph against some other data using matplotlib.
My code is
import numpy as np
import matplotlib.pyplot as plt
with open("file path",'r') as f:
s= f.readlines()
y=(s[0])
x=np.arange(0.00,9.04,0.04)
plt.plot(x,y)
plt.ylabel('Probability Distribution')
plt.xlabel('Photometric Redshift')
plt.title('r2')
plt.show()
I get the following error message
Traceback (most recent call last):
File "dsl_2_python.py", line 36, in <module>
plt.plot(x,y)
File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 2817, in plot
ret = ax.plot(*args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/axes.py", line 3996, in plot
for line in self._get_lines(*args, **kwargs):
File "/usr/lib64/python2.7/site-packages/matplotlib/axes.py", line 330, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "/usr/lib64/python2.7/site-packages/matplotlib/axes.py", line 289, in _plot_args
linestyle, marker, color = _process_plot_format(tup[-1])
File "/usr/lib64/python2.7/site-packages/matplotlib/axes.py", line 126, in _process_plot_format
'Unrecognized character %c in format string' % c)
ValueError: Unrecognized character 0 in format string
>
I think it is something to do with y being a string not a list, but s seems to be a list, so I don't know why y becomes a string or how to make it a list. Can anyone help?
f?