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, 2019 in Python by Krish
6,267 views

1 answer to this question.

+1 vote

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')

df.drop_duplicates('Make',inplace=True)

df.sort_values(by='count',ascending=False,inplace=True)

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

plt.figure(figsize=(50,8))

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) 

plt.show()

answered Jul 22, 2019 by Shri

Hi , Please help

i have created one chart using panda, below code

import matplotlib.pyplot as plt

import pandas as pd

df = pd.read_csv('C:/Users/aku396/test3.csv',delimiter=',')

#drop the column which are not require.

df = df.drop(['Operational Tier 2'],axis=1)

#based on make count the number of models

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

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

plt.figure(figsize=(50,8))

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

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

plt.show()

Problem is that it took other and Database/Data individually
Please share the structure of the csv file. If there are multiple columns named Other and Database/Data then you will have to append them and create one dataframe for "Others" and another dataframe for "Database/Data" and then plot the chart.

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
• 58,090 points
4,687 views
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, 2019 in Python by Mohammad
• 3,230 points
850 views
+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,890 points
19,350 views
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, 2019 in Python by Himanshu
1,953 views
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, 2019 in Python by anonymous

edited May 27, 2019 by Kalgi 1,719 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,300 points
517 views
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, 2019 in Python by Junaid
1,785 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP