How to Fix: TypeError: no numeric data to plot Last Updated : 28 Nov, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will fix the error: TypeError: no numeric data to plot Cases of this error occurrence: Python3 # importing pandas import pandas as pd # importing numpy import numpy as np import matplotlib.pyplot as plt petal_length = ['3.3', '3.5', '4.0', '4.5', '4.6', '5.0', '5.5', '6.0', '6.5', '7.0'] petal_width = ['3.6', '3.8', '4.4', '6.6', '6.8', '7.0', '7.5', '8.0', '8.5', '8.9'] df = pd.DataFrame({'petal_length(cm)': petal_length, 'petal_width(cm)': petal_width}) df.plot(x='petal_length(cm)', y='petal_width(cm)') plt.show() Output: TypeError: no numeric data to plotReason for the error : Plotting can be done only on numeric data when we plot the data with datatype different that numeric data this error raises. To know whether the data types are numeric or not we can know it by using the function dtypes(). print(df.dtypes) The data that we use to plot must be numeric. Fixing the error: This error can be fixed by converting the data to be plotted into numeric data. To convert the data to numeric data we can use the functions astype() or to_numeric(). Method 1 : Using astype() function Syntax: df['column_name']= df['column_name'].astype(data_type) where, df is the input dataframe Example: Python3 # importing pandas import pandas as pd # importing numpy import numpy as np # importing matplotlib.pyplot import matplotlib.pyplot as plt petal_length = ['3.3', '3.5', '4.0', '4.5', '4.6', '5.0', '5.5', '6.0', '6.5', '7.0'] petal_width = ['3.6', '3.8', '4.4', '6.6', '6.8', '7.0', '7.5', '8.0', '8.5', '8.9'] df = pd.DataFrame({'petal_length(cm)': petal_length, 'petal_width(cm)': petal_width}) df['petal_length(cm)'] = df['petal_length(cm)'].astype(float) df['petal_width(cm)'] = df['petal_width(cm)'].astype(float) df.plot(x='petal_length(cm)', y='petal_width(cm)') plt.show() Output: Method 2 :Using to_numeric() function Syntax: df['column_name'] = pd.to_numeric(df['column_name']) where df is the input dataframe Example: Python3 # importing pandas import pandas as pd # importing numpy import numpy as np # importing matplotlib.pyplot import matplotlib.pyplot as plt petal_length = ['3.3', '3.5', '4.0', '4.5', '4.6', '5.0', '5.5', '6.0', '6.5', '7.0'] petal_width = ['3.6', '3.8', '4.4', '6.6', '6.8', '7.0', '7.5', '8.0', '8.5', '8.9'] df = pd.DataFrame({'petal_length(cm)': petal_length, 'petal_width(cm)': petal_width}) # Using to_numeric() function df['petal_length(cm)'] = pd.to_numeric(df['petal_length(cm)']) df['petal_width(cm)'] = pd.to_numeric(df['petal_width(cm)']) df.plot(x='petal_length(cm)', y='petal_width(cm)') plt.show() Output: Comment More infoAdvertise with us Next Article How to Fix: TypeError: no numeric data to plot L lokeshpotta20 Follow Improve Article Tags : Python Python-pandas Python How-to-fix Practice Tags : python Similar Reads How to Fix "Can't Adapt Type 'numpy.int64'"? The error is âCanât adapt type ânumpy. int64ââ and occurs when the NumPy data types specific to a language are incompatible with other database or library types expected. This can be solved where, NumPy types are converted to native Python types or where one use the procedure of adaptation. All of t 5 min read How to Fix "TypeError: 'float' object is not callable" in Python In Python, encountering the error message "TypeError: 'float' object is not callable" is a common issue that can arise due to the misuse of the variable names or syntax errors. This article will explain why this error occurs and provide detailed steps to fix it along with the example code and common 3 min read How to read a numerical data or file in Python with numpy? Prerequisites: Numpy NumPy is a general-purpose array-processing package. It provides a high-performance multidimensional array object and tools for working with these arrays. This article depicts how numeric data can be read from a file using Numpy. Numerical data can be present in different forma 4 min read How to Fix "TypeError: 'Column' Object is Not Callable" in Python Pandas The error "TypeError: 'Column' object is not callable" in Python typically occurs when you try to call a Column object as if it were a function. This error commonly arises when working with the libraries like Pandas or SQLAlchemy. However, users often encounter various errors when manipulating data, 3 min read How to Fix: âxâ must be numeric in R In this article, we are going to see how to fix: 'x' must be numeric. For this we will cover two example for the error message âx must be numericâ. Example 1: Error in vector 'x' must be numeric In this example, we will create a vector and try to plot a hist() plot with particular data and then occu 2 min read Like