Skip to content

Commit 7dc773d

Browse files
Add files via upload
Last change on 20190307
1 parent 33ee097 commit 7dc773d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+7050
-0
lines changed

course_code_matplot/3dplot.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
from mpl_toolkits.mplot3d import Axes3D
4+
fig = plt.figure()
5+
ax = fig.add_subplot(111, projection='3d')
6+
7+
x1 = np.random.rand(100)
8+
y1 = np.random.rand(100)
9+
z1 = np.random.rand(100)
10+
ax.scatter(x1,y1,z1,s=20, color='red')
11+
12+
plt.show()

course_code_matplot/3dplot2.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
from mpl_toolkits.mplot3d import Axes3D
4+
fig = plt.figure()
5+
ax = fig.add_subplot(111, projection='3d')
6+
7+
x1 = np.random.rand(10)
8+
y1 = np.random.rand(10)
9+
z1 = np.random.rand(10)
10+
11+
x2 = np.random.rand(10)
12+
y2 = np.random.rand(10)
13+
z2 = np.random.rand(10)
14+
15+
ax.scatter(x1,y1,z1,s=20, color='red', marker='^')
16+
ax.scatter(x2,y2,z2,s=20, color='blue', marker='o')
17+
18+
plt.show()

course_code_matplot/bar.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import matplotlib.pyplot as plt
2+
3+
x1 = [1,2,3,4,5]
4+
y1 = [1,2,4,8,16]
5+
6+
colors = [ 'green', 'red', 'blue', 'orange', 'lightblue']
7+
8+
plt.bar(x1,y1,edgecolor='black',color=colors, linewidth=2)
9+
plt.title('Your title')
10+
plt.xlabel('Horizontal title')
11+
plt.ylabel('Vertical title')
12+
plt.show()

course_code_matplot/fill.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
4+
X = np.arange(0,10)
5+
Y1 = 0.05*X*X
6+
7+
plt.ylim(0, 5)
8+
plt.plot(X, Y1, color='blue')
9+
plt.fill_between(X, Y1, color='red', alpha='0.5')
10+
plt.show()

course_code_matplot/fill2.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
4+
X = np.arange(0,10)
5+
Y1 = 0.05*X*X
6+
Y2 = 0.03*X*X
7+
8+
plt.ylim(0, 5)
9+
plt.plot(X, Y1, color='blue')
10+
plt.plot(X, Y2, color='red')
11+
plt.fill_between(X, Y1, Y2, color='red', alpha='0.5')
12+
plt.show()

course_code_matplot/grid.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import matplotlib.pyplot as plt
2+
3+
x1 = [1,2,3,4,5]
4+
y1 = [1,2,4,8,16]
5+
6+
plt.plot(x1, y1, 'ro--', label='students')
7+
plt.legend(loc='best')
8+
plt.title('Your title')
9+
plt.xlabel('Horizontal title')
10+
plt.ylabel('Vertical title')
11+
plt.grid(which='major',linestyle='-', color='black')
12+
plt.minorticks_on()
13+
plt.grid(which='minor',linestyle='--', color='gray', alpha=0.2)
14+
plt.show()

course_code_matplot/legend-example.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import matplotlib.pyplot as plt
2+
3+
x1 = [1,2,3,4,5]
4+
y1 = [1,2,4,8,16]
5+
y2 = [1,1,2,3,5]
6+
7+
plt.plot(x1, y1, 'ro-', label='students')
8+
plt.plot(x1, y2, 'b^-', label='teachers')
9+
10+
plt.subplots_adjust(left=0.3, bottom=0.3)
11+
plt.legend(bbox_to_anchor=(-0.15, 0.17), loc='upper right')
12+
13+
plt.title('Your title')
14+
plt.xlabel('Horizontal title')
15+
plt.ylabel('Vertical title')
16+
plt.grid(True)
17+
plt.show()

course_code_matplot/lineplot.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import matplotlib.pyplot as plt
2+
3+
x1 = [1,2,3,4,5]
4+
y1 = [1,2,4,8,16]
5+
6+
plt.plot(x1, y1, 'ro--', label='students')
7+
plt.title('Your title')
8+
plt.xlabel('Horizontal title')
9+
plt.ylabel('Vertical title')
10+
plt.show()

course_code_matplot/loadFromExcel.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pandas as pd
2+
from pandas import ExcelFile
3+
4+
df = pd.read_excel('data.xlsx', sheetname='Sheet1')
5+
6+
X = list(df['X'])
7+
Y = list(df['Y'])

course_code_matplot/loadFromFile.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
X = []
2+
Y = []
3+
4+
with open('values.txt','r') as myfile:
5+
for line in myfile:
6+
Y.append( int(line) )
7+
8+
X = list(range(0,len(Y)+1))
9+
print(X)
10+
print(Y)

course_code_matplot/multilineplot.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import matplotlib.pyplot as plt
2+
3+
x1 = [1,2,3,4,5]
4+
y1 = [1,2,4,8,16]
5+
6+
x2 = [1,2,3,4,5]
7+
y2 = [1,3,9,13,16]
8+
9+
x3 = [1,2,3,4,5]
10+
y3 = [2,4,6,8,10]
11+
12+
plt.plot(x1, y1, 'ro--', label='students')
13+
plt.plot(x2, y2, 'b^-', label='grades')
14+
plt.plot(x3, y3, 'g-', label='visitors')
15+
plt.legend(loc='best')
16+
17+
plt.title('Your title')
18+
plt.xlabel('Horizontal title')
19+
plt.ylabel('Vertical title')
20+
plt.show()

course_code_matplot/pie.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import matplotlib.pyplot as plt
2+
3+
values = [16,18,4,8]
4+
pielabels = ['Python', 'Ruby', 'Java', 'Perl']
5+
piecolors = ['red','orange','yellow','maroon']
6+
pieexplode = [0,0.1,0,0]
7+
8+
plt.pie(values, labels=pielabels,explode=pieexplode,colors=piecolors,startangle=0,shadow=True)
9+
plt.title('Pie Chart')
10+
plt.xlabel('Horizontal title')
11+
plt.ylabel('Vertical title')
12+
plt.legend(loc='best')
13+
plt.show()

course_code_matplot/scatterplot.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
import seaborn as sns
4+
sns.set_style("darkgrid")
5+
6+
N = 50
7+
x1 = np.random.rand(N)
8+
y1 = np.random.rand(N)
9+
s1 = np.random.rand(N) * 300
10+
x2 = np.random.rand(N)
11+
y2 = np.random.rand(N)
12+
s2 = np.random.rand(N) * 300
13+
14+
plt.scatter(x1, y1,s=s1)
15+
plt.scatter(x2, y2,s=s2)
16+
plt.title('Your title')
17+
plt.xlabel('Horizontal title')
18+
plt.ylabel('Vertical title')
19+
plt.show()

course_code_matplot/style.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import matplotlib.pyplot as plt
2+
3+
plt.style.use('ggplot')
4+
print(plt.style.available)
5+
6+
x1 = [1,2,3,4,5]
7+
y1 = [1,2,4,8,16]
8+
9+
plt.bar(x1,y1)
10+
plt.title('Your title')
11+
plt.xlabel('Horizontal title')
12+
plt.ylabel('Vertical title')
13+
plt.show()

course_code_matplot/style2.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import matplotlib.pyplot as plt
2+
import seaborn as sns
3+
4+
sns.set_style("darkgrid")
5+
6+
x1 = [1,2,3,4,5]
7+
y1 = [1,2,4,8,16]
8+
9+
plt.bar(x1,y1)
10+
plt.title('Your title')
11+
plt.xlabel('Horizontal title')
12+
plt.ylabel('Vertical title')
13+
plt.show()

course_code_matplot/style2_plot2.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import matplotlib.pyplot as plt
2+
3+
x1 = [1,2,3,4,5]
4+
y1 = [1,2,4,8,16]
5+
6+
x2 = [1,2,3,4,5]
7+
y2 = [1,3,9,13,16]
8+
9+
x3 = [1,2,3,4,5]
10+
y3 = [2,4,6,8,10]
11+
12+
plt.plot(x1, y1, 'ro--', label='students')
13+
plt.plot(x2, y2, 'b^-', label='grades')
14+
plt.plot(x3, y3, 'g-', label='visitors')
15+
plt.legend(loc='best')
16+
17+
plt.title('Your title')
18+
plt.xlabel('Horizontal title')
19+
plt.ylabel('Vertical title')
20+
plt.show()

course_code_matplot/subplots.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
4+
x = [1,2,3]
5+
y = [1,2,3]
6+
7+
fig = plt.figure()
8+
fig.suptitle('Plot Title')
9+
10+
plt.subplot(2,2,1)
11+
plt.plot(x,y)
12+
plt.xlabel('x1')
13+
plt.ylabel('y1')
14+
15+
plt.subplot(2,2,2)
16+
plt.plot(x,y, color='red')
17+
plt.xlabel('x2')
18+
plt.ylabel('y2')
19+
20+
plt.subplot(2,2,3)
21+
plt.plot(x,y, color='red')
22+
plt.xlabel('x2')
23+
plt.ylabel('y2')
24+
25+
plt.subplot(2,2,4)
26+
plt.plot(x,y, color='red')
27+
plt.xlabel('x2')
28+
plt.ylabel('y2')
29+
30+
31+
plt.show()

data_myself/data.xlsx

8.88 KB
Binary file not shown.

data_myself/values.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
10
2+
20
3+
30
4+
40
5+
50

0 commit comments

Comments
 (0)