Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions M/matplotlib_files/bar1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import matplotlib.pyplot as plt
import numpy as np

cities=['delhi','mumbai','bangalore','cuttack']
population1=[2.5,3,4,1]
population2=[2,3.7,3,6]
population3=[1.4,2.8,2,1]
x=np.arange(len(cities))
plt.bar(x-0.3,population1,width=0.3)
plt.bar(cities,population2,width=0.3)
plt.bar(x+0.3,population3,width=0.3)
plt.xlabel('cities')
plt.xlabel('population')
plt.title('multiple bargraph')
plt.grid()
plt.show()
28 changes: 28 additions & 0 deletions M/matplotlib_files/bar2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

d1={'name':['omm','shakti','arya','satyakam'],'age':[13,14,14,15],'height':[170,172,168,174],'weight':[60,62,65,62]}
df1=pd.DataFrame(d1)

x = np.arange(len(df1['name']))
width = 0.3

# ensure output directory exists (inside the matplotlib_files folder)
script_dir = os.path.dirname(os.path.abspath(__file__))
graphs_dir = os.path.join(script_dir, 'graphs')
os.makedirs(graphs_dir, exist_ok=True)

plt.bar(x - width, df1['age'], width=width, color='#e25625', label='age')
plt.bar(x, df1['height'], width=width, color='#100900', label='height')
plt.bar(x + width, df1['weight'], width=width, color='#2596be', label='weight')

# show names at the numeric x positions
plt.xticks(x, df1['name'])

plt.xlabel('studentName')
plt.ylabel('studentData')
plt.legend(loc='upper right') #to show the color code in graph
plt.savefig(os.path.join(graphs_dir, 'fig_6.png'))
plt.show()
Binary file added M/matplotlib_files/graphs/fig_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions M/matplotlib_files/hist1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import matplotlib.pyplot as plt
import numpy as np

x=np.linspace(1,20,300) # takes 300 values betwn 1-20
plt.hist(x,bins=20)
plt.show()
9 changes: 9 additions & 0 deletions M/matplotlib_files/line1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import matplotlib.pyplot as plt
import numpy as np

x=[1,2,3,4,5]
y=[1,2,3,4,5]
plt.plot(x,y,'r*',linestyle='dotted',markersize=20,mec='k',mfc='g') #mec=markeredgecolor, mfc=markerfacecolor
plt.xlabel('students')
plt.ylabel('marks')
plt.show()
11 changes: 11 additions & 0 deletions M/matplotlib_files/pie1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import matplotlib.pyplot as plt

popl = [1325, 338, 8]
contri = ['India', 'USA', 'Sweden']
clr = ['gold', 'pink', 'black']
xpld = [0.3, 0.3, 0.3]
plt.pie(popl, colors=clr, labels=contri,
shadow=True, explode=xpld, autopct='%4.1f%%')
plt.title('population in millions')

plt.show()
10 changes: 10 additions & 0 deletions M/matplotlib_files/plt1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import matplotlib.pyplot as plt
import numpy as np

cities=['delhi','mumbai','bangalore','cuttack']
population=[2.5,3,4,1]
plt.bar(cities,population,width=0.3,color=['r','silver','gold','brown'])
plt.plot(cities,population,'ro',linestyle='dashed')
plt.xlabel('cities')
plt.xlabel('population')
plt.show()
9 changes: 9 additions & 0 deletions M/matplotlib_files/sctr1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import matplotlib.pyplot as plt
import numpy as np

x=np.random.randint(0,100,size=(100,))
y=np.random.randint(0,100,size=(100,))
size=range(0,100)
clr=['r','c','k','g']*25 #no of colors must be same as the size
plt.scatter(x,y,s=size,c=clr)
plt.show()