简体   繁体   中英

How to use matplotlib to plot line charts

I use pandas to read my csv file and turn two columns into arrays as independent/dependent variables respectively. the data reading, array-turning trans and value assign

Then when I want to use matplotlib.pyplot to plot the line charts out, it turns out that 'numpy.ndarray' objects has no attribute 'find'.

import numpy as np
import matplotlib.pyplot as plt
plt.plot(x,y)

The problem is probably with your dtypes , assuming your data are in df check the df.dtypes . Columns you are trying to plot must be numeric ( float , int , bool ).

I guess that at least one of the columns you are plotting has object dtype, try to find out why (maybe missing values were read as some sort of string, or everything is just considered string) and convert it to correct type with astype , ie

df['float_col'] = df['float_col'].astype(np.float64)

Edit:

If you are trying to plot date use, make sure that dtype is actually a date ie datetime64[ns] and use matplotlib s dedicated method plot_date

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM