コード例 #1
0
def draw_pie(grades):
    labels = ['A', 'B', 'C', 'D', 'E']
    gradeGroup = {}
    for grade in grades:
        gradeGroup[grade] = gradeGroup.get(grade, 0) + 1
    #创建饼形图
    #第一个参数为扇形的面积
    #labels参数为扇形的说明文字
    #autopct参数为扇形占比的显示格式
    plt.pie([gradeGroup.get(label, 0) for label in labels], labels=labels, autopct='%1.1f%%')
    plt.title('Grades Of Male Students')
    plt.show()
コード例 #2
0
visual_unique_countries.append('Others')
visual_confirmed_cases.append(others) 


# Visualize the 10 countries
plt.figure(figsize=(32, 18))
plt.barh(visual_unique_countries, visual_confirmed_cases)
plt.title('Number of Covid-19 Confirmed Cases in Countries/Regions',size=20)
plt.show()


# Create a pie chart to see the total confirmed cases in 10 different countries
c = random.choices(list(mcolors.CSS4_COLORS.values()),k = len()unique_countries) 
plt.figure(figsize=(20,20))
plt.title('Covid-19 Confirmed Cases per Country')
plt.pie(visual_confirmed_cases,colors=c)
plt.legend(visual_unique_countries,loc='best')
plt.show()


# Create a pie chart to see the total confirmed cases in 10 different countries outside china

c = random.choices(len(mcolors.CSS4_COLORS.values()), k = len(unique_countries)) 
plt.figure(figsize=(20,20))
plt.title('Covid-19 Confirmed Cases in Countries Outside of Mainlend China')
plt.pie(visual_confirmed_cases[1:], colors=c)
plt.legend(visual_unique_countries[1:],loc = 'best')
plt.show()

# Building the SVM model
コード例 #3
0
import matplotlib.pylot as plt

labels = 'Python', 'C++', 'Ruby', 'Java', 'PHP', 'Perl'
sizes = [33, 52, 12, 17, 62, 48]
separated = (.1, .3, 0, 0, .6, 0)

plt.pie(sizes, labels=labels, autopct='%1.1f%%', explode=separated)
plt.axis('equal')

plt.show()
コード例 #4
0
negative = percentage(negative, noOfSearchTerms)
neutral = percentage(neutral, noOfSearchTerms)

positive = format(positive, '.2f')
negative = format(negative, '.2f')
neutral = format(neutral, '.2f')

print("How are poeple reacting on " + searchTerm + " by analyzing " +
      str(noOfSearchTerms) + "Tweets.")

if (polarity == 0.00):
    print("Neutral")
elif (polarity < 0.00):
    print("Negative")
elif (polarity > 0.00):
    print("Positive")

labels = [
    'Positive [' + str(positive) + '%]', 'Neutral [' + str(neutral) + '%]',
    'Negative [' + str(negative) + '%]'
]
sizes = [positive, neutral, negative]
colors = ['yellowgreen', 'gold', 'red']
patches, texts = plt.pie(sizes, colors=colors, startangle=90)
plt.legend(patches, labels, loc="best")
plt.title('How people are reacting on ' + searchTerm + ' by analyzing ' +
          str(noOfSearchTerms) + ' Tweets.')
plt.axis('equal')
plt.tight.layout()
plt.show()
コード例 #5
0
import covid
import matplotlib.pylot as plt   

cov=covid.Covid()

name = input("ENTER the country name")
print(name)
virusdata=covid.get_status_by_country
active=virusdata['active']
recover=virusdata['recovered']
deaths=virusdata['deaths']
plt.pie([active,recover,deaths]).labels
plt.title(name)
plt.legend()
plt.show
コード例 #6
0
import matplotlib.pylot as plt
inport pandas as pd

raw_data={'name': ['Nick','Cedric','Jules', 'Donald'],
          'jan_ir': [124, 112, 110, 180],
          'feb_ir': [122, 132, 144, 98],
          'march_ir': [65, 88, 12, 32]}

df = pd.DataFrame(raw_data, columns=['name','jan_ir', 'feb_ir', 'march_ir'])

df['total_ir'] = df['jan_ir'] + df['feb_ir'] + df['march_ir']

color = [(1, .4, .4), (1, .6, 1), (.5, .3, 1), (.3, 1, .5)]

plt.pie(df['total_ir'], labels=df['names'], colors=color, autopct='%1.1f%%')
plt.show()

print(df)
コード例 #7
0
percent_popular = len(np_ratings[popular_apps]) / len(np_ratings) * 100
print("percent_popular")

unpopular_apps = np_ratings < 4
print("percent_unpopular", len(np_ratings[unpopular_apps]))

percent_unpopular = 100 - (np_ratings[unpopular_apps]) / len(np_ratings) * 100
print("percent_unpopular")

somewhat_popular = 100 - (percent_popular + percent_unpopular)
print("somewhat_popular")

# do a visualization with out new data
labels = "Sucks", "Meh", "Love it!"
sizes = [unpopular_apps, somewhat_popular, popular_apps]
colors = ['yellowgreen', 'lightgreen', 'lightskyblue']
explode = (0.1, 0.1, 0.15)

plt.pie(sizes, explode=explode, colors=color, autopct='%1.1%', shadow=True, startangle=140)

plt.axis('equal')
plt.legend(labels, loc=1)
plt.title("Do we love our apps?")
plt.xlabel("User Ratings - App Installs (10,000+ apps)")
plt.show()

# print ('processed', line_count, 'lines of data')
print(categories)
print('first row of data', installs [0])
print('last row of data', installs [-1])