In [4]:
import numpy as np
import matplotlib.pyplot as plt
year = [1960, 1970, 1980, 1990, 2000, 2010]
pop_china = [682, 825, 994, 1170, 1280, 1360]
pop_usa = [179, 210, 230, 253, 282, 309]
pop_india = [449.48, 553.57, 696.783, 870.133, 1000.4, 1309.1]
plt.plot(year, pop_china, color='red', label='China')
plt.plot(year, pop_india, color='orange', label='India')
plt.plot(year, pop_usa, color='blue', label='U.S.A')
plt.xlabel('Countries')
plt.ylabel('Population in million')
plt.title('Populations of Three Nations 1960 - 2010')
plt.rcParams["figure.figsize"] = [30,40]
plt.legend()
plt.show()
In [11]:
import numpy as np
import matplotlib.pyplot as plt
# data to plot
n_groups = 4
wins = (13, 9, 7, 0)
lossess = (3, 7, 9, 16)
# create plot
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = .2
opacity = 0.8
rects1 = plt.bar(index, wins, bar_width,
alpha=opacity,
color='green',
label='Wins')
rects2 = plt.bar(index + bar_width, lossess, bar_width,
alpha=opacity,
color='red',
label='Losses')
plt.xlabel('Teams')
plt.ylabel('Record')
plt.title('AFC North Records 2017')
plt.xticks(index + bar_width, ('Steelers', 'Bengals', 'Ravens', 'Browns'))
plt.legend()
plt.rcParams["figure.figsize"] = [8, 8]
plt.tight_layout()
plt.show()
In [12]:
import matplotlib.pyplot as plt
# Pie chart, where the slices will be ordered and plotted counter-clockwise:
labels = 'Sleeping', 'Surfing', 'Studying', 'Crying', 'Playing Video Games'
sizes = [10, 20, 15, 15, 40]
explode = (0, 0, 0, 0, 0)
fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90)
ax1.set(aspect="equal", title="How I'm spending my Last Semester")
#ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
plt.rcParams["figure.figsize"] = [30,40]
plt.show()
In [13]:
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# Create a list of word
text=('''Is this the real life Is this just fantasy Caught in a landslide No escape from reality Open your eyes Look up to the skies and see I'm just a poor boy, I need no sympathy Because I'm easy come, easy go A little high, little low Anyway the wind blows, doesn't really matter to me, to me Mama, just killed a man Put a gun against his head
Pulled my trigger, now he's dead
Mama, life had just begun
But now I've gone and thrown it all away
Mama, ooo
Didn't mean to make you cry
If I'm not back again this time tomorrow
Carry on, carry on, as if nothing really matters
Too late, my time has come
Sends shivers down my spine
Body's aching all the time
Goodbye everybody I've got to go
Gotta leave you all behind and face the truth
Mama, ooo (anyway the wind blows)
I don't want to die
I sometimes wish I'd never been born at all
I see a little silhouetto of a man
Scaramouch, scaramouch will you do the fandango
Thunderbolt and lightning very very frightening me
Gallileo, Gallileo,
Gallileo, Gallileo,
Gallileo Figaro - magnifico
But I'm just a poor boy and nobody loves me
He's just a poor boy from a poor family
Spare him his life from this monstrosity
Easy come easy go will you let me go
Bismillah! No we will not let you go - let him go
Bismillah! We will not let you go - let him go
Bismillah! We will not let you go let me go Will not let you go let me go (never)
Never let you go let me go
Never let me go ooo
No, no, no, no, no, no, no
Oh mama mia, mama mia, mama mia let me go
Beelzebub has a devil put aside for me
For me
For me
So you think you can stone me and spit in my eye
So you think you can love me and leave me to die
Oh baby, can't do this to me baby
Just gotta get out just gotta get right outta here Ooh yeah, ooh yeah Nothing really matters Anyone can see Nothing really matters nothing really matters to me Anyway the wind blows''')
# Create the wordcloud object
wordcloud = WordCloud(width=1600, height=800, margin=0).generate(text)
# Display the generated image:
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.margins(x=0, y=0)
plt.rcParams["figure.figsize"] = [30,40]
plt.show()
In [14]:
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# Create a list of word
text=('''Gucci Gang, ooh, yeah, Lil Pump, yeah, Gucci Gang, ooh
Gucci gang, Gucci gang, Gucci gang, Gucci gang
Gucci gang, Gucci gang, Gucci gang (Gucci gang!)
Spend ten racks on a new chain
My love do cocaine, ooh
I a, I forgot her name
I can't buy a no wedding ring
Rather go and buy Balmains
Gucci gang, Gucci gang, Gucci gang (Gucci gang!)
Gucci gang, Gucci gang, Gucci gang, Gucci gang
Gucci gang, Gucci gang, Gucci gang (Gucci gang!)
Spend ten racks on a new chain
My love do cocaine, ooh
I a, I forgot her name, yeah
I can't buy no no wedding ring
Rather go and buy Balmains, aye
Gucci gang, Gucci gang, Gucci gang
My lean cost more than your rent, ooh
Your mama still live in a tent, yeah
Still slanging dope in the jets, huh
Me and my grandma take meds, ooh
None of this shit be new to me
my teacher, call it tutory
Bought some red bottoms, cost hella Gs
your airline, your company
, your breath smell like some cigarettes
I'd rather a from the projects
They kicked me out the plane off a Percocet
Now Lil Pump fly a private jet
Everybody screaming " West Jet!"
Lil Pump still sell that meth
Hunnid on my wrist sippin on Tech
a lil, make her pussy wet
Gucci gang, Gucci gang, Gucci gang, Gucci gang
Gucci gang, Gucci gang, Gucci gang (Gucci gang!)
Spend ten racks on a new chain
My love do cocaine, ooh
I a , I forgot her name
I can't buy a no wedding ring
Rather go and buy Balmains
Gucci gang, Gucci gang, Gucci gang (Gucci gang!)
Gucci gang, Gucci gang, Gucci gang, Gucci gang
Gucci gang, Gucci gang, Gucci gang (Gucci gang!)
Spend ten racks on a new chain
My love do cocaine, ooh
I a , I forgot her name
I can't buy no no wedding ring
Rather go and buy Balmains, aye
Gucci gang, Gucci gang, Gucci gang
Lil Pump, yeah, Lil Pump, ooh''')
# Create the wordcloud object
wordcloud = WordCloud(width=1500, height=800, margin=0).generate(text)
# Display the generated image:
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.margins(x=0, y=0)
plt.rcParams["figure.figsize"] = [30,40]
plt.show()
In [20]:
import matplotlib.pyplot as plt
import numpy as np
with plt.xkcd():
# Based on "Stove Ownership" from XKCD by Randall Monroe
# http://xkcd.com/418/
fig = plt.figure()
ax = fig.add_axes((0.1, 0.2, 0.8, 0.7))
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.xticks([])
plt.yticks([])
ax.set_ylim([-30, 10])
data = np.ones(100)
data[70:] -= np.arange(30)
plt.annotate(
'THE DAY I REALIZED\nI COULD COOK BACON\nWHENEVER I WANTED',
xy=(70, 1), arrowprops=dict(arrowstyle='->'), xytext=(15, -10))
plt.plot(data)
plt.xlabel('time')
plt.ylabel('my overall health')
fig.text(
0.5, 0.05,
'"Stove Ownership" from xkcd by Randall Monroe',
ha='center')
plt.show()
In [18]:
import matplotlib.pyplot as plt
import numpy as np
with plt.xkcd():
# Based on "The Data So Far" from XKCD by Randall Monroe
# http://xkcd.com/373/
fig = plt.figure()
ax = fig.add_axes((0.1, 0.2, 0.8, 0.7))
ax.bar([0, 1], [0, 100], 0.25)
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.set_xticks([0, 1])
ax.set_xlim([-0.5, 1.5])
ax.set_ylim([0, 110])
ax.set_xticklabels(['CONFIRMED BY\nEXPERIMENT', 'REFUTED BY\nEXPERIMENT'])
plt.yticks([])
plt.title("CLAIMS OF SUPERNATURAL POWERS")
plt.show()
In [ ]: