python - Error with matplotlib when used with Unicode strings -


Text after "

I have a file containing text Unicode string and their frequencies.

> >

Code>

I'm having this error

  traceback (last call last): file "plot.py", line 3,  

I have this code

  plt xs, ys = np .loadtxt ('oun.txt', delimiter = '\ t'). Imported as np import matplotlib.pyplot as T-plt.bar (XS, numpy, ys) plt.show ()  

What is wrong with this code?

To read the string from a file using loadtxt The code> dtype must specify the argument (see here).

  ('wire', 'freq'), 'format': np data = np.loadtxt ('derp', dtype = {'name' as plt import numpy Import matplotlib.pyplot ('S32', 'I4')}) Xs, ys = zip (* data) temp = range (len (ys)) temp variable to use as X-axis Plt.bar ( Temp, ys, align = 'center') plt.xticks (temp, xs) # Redefine your strings. Plt.show ()  

In this case there are 2 columns in the file, I can call them names ('strings', 'freq') And formats are ('s32', 'i4') where s is a string and i to an integer Indicates documents can be found for dtype . Note that the numbers in formatting dtype gives information about the value of the values ​​in your column (" i4 " matches a 32-bit signed integer for example) .


Comments