Numpy Error when trying to plot a histogram

47 views Asked by At

I am trying to plot a histogram with this code. Python is giving me an error in line 1.

numpy.genfromtxt('dataset1.txt', dtype=<type 'float'>,
comments='#', delimiter=None, skip_header=0,
skip_footer=0, missing_values=None,
filling_values=None, usecols=None, unpack=None)
plt.errorbar(x,y, yerr=yErr)
ls='',marker='.'
errorevery=n
numpy.polyfit(x,y,degr,w=None)
plt.xlabel('An arbitrary x-value')
plt.ylabel('A Gaussian y-value')
plt.title('One fine Gaussian')
1

There are 1 answers

0
hpaulj On

The first line produces:

In [1]: import numpy as np

In [2]: np.genfromtxt('dataset1.txt', dtype=<type 'float'>,
   ...: comments='#', delimiter=None, skip_header=0,
   ...: skip_footer=0, missing_values=None,
   ...: filling_values=None, usecols=None, unpack=None)
  Cell In[2], line 1
    np.genfromtxt('dataset1.txt', dtype=<type 'float'>,
                                        ^
SyntaxError: invalid syntax

syntax error means it fails the first step, reading the string and figuring what it is in basic python terms. Note the tick, ^ under '<type...>'. This isn't valid python notation. As comments say, it's a documenation way of saying put something like 'float' or 'int' here.

Sooner of later you need to learn basic python, and how to read documenation of functions like this.

AND write SO questions with enough information.