Plot a pie-chart in Python in Matplotlib

0 votes

I am trying to plot a pie-chart of the number of models released by every manufacturer, recorded in the data provided. Also, mention the name of the manufacture with the largest releases. Need help on this. I am not able to do it.

car = pd.read_csv("Cars2015.csv")
plt.pie(y, labels=label, autopct="%1.1f%%", shadow=True, startangle=140)

this my code but it gives a different picture

Jul 22 in Python by Krish

1 answer to this question.

0 votes

Not sure which dataset you are using. But here's a sample code for your reference:

Please find the below code to solve this problem statement.

import matplotlib.pyplot as plt

import pandas as pd

df = pd.read_csv('C:/Users/ed110374/Desktop/faltu stuff/Cars2015.csv',delimiter=',')

#drop the column which are not require.

df = df.drop(['Model','Type','LowPrice','HighPrice','Drive','CityMPG','HwyMPG','FuelCap','Length'], axis=1)

df = df.drop(['Width','Wheelbase','Height','UTurn','Weight','Acc030','Acc060'],axis=1)

df = df.drop(['QtrMile','PageNum','Size'],axis=1)

#based on make count the number of models

df['count'] = df.groupby('Make')['Make'].transform('count')



#Based on the count obtain we will plot our graph.


ax1 = plt.subplot(121, aspect='equal')

df.plot(kind='pie', y = 'count', ax=ax1, autopct='%1.1f%%',startangle=90, shadow=False, labels=df['Make'], legend = False, fontsize=10)

answered Jul 22 by Shri

Related Questions In Python

0 votes
1 answer

Plot a k-distance graph in python

You probably want to use the matrix ...READ MORE

answered Sep 5, 2018 in Python by Priyaj
• 56,520 points
0 votes
1 answer

how to plot a boxplot in python using seaborn?

following is the syntax for a boxplot ...READ MORE

answered Aug 13 in Python by Mohammad
• 3,060 points
+3 votes
7 answers

How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

answered Mar 31, 2018 in Python by DareDev
• 6,810 points
0 votes
1 answer

Example code for creating broken barh graph using matplotlib

Try this, it should work well. import matplotlib.pyplot ...READ MORE

answered May 27 in Python by Himanshu
0 votes
1 answer
0 votes
1 answer

An example showing how to plot the coherence of two signals

This should work well: import numpy as np import ...READ MORE

answered May 27 in Python by anonymous

edited May 27 by Kalgi 33 views
0 votes
1 answer

Is there a string 'contains' in python?

In this case, you can use the ...READ MORE

answered Sep 25, 2018 in Python by SDeb
• 13,160 points
0 votes
1 answer

Is there a way to list out in-built variables and functions of Python?

The in-built variables and functions are defined ...READ MORE

answered May 14 in Python by Junaid