- test1.py
- #!/usr/bin/env python3
- import matplotlib.pyplot as plt
- import numpy as np
- x = np.linspace(0, 10, 10)
- y = np.sin(x)
- plt.plot(x, y)
- plt.xlabel('time')
- plt.ylabel('Some function of time')
- plt.title("My cool chart")
- plt.show()
ScatterPlot
- test2.py
- #!/usr/bin/env python3
- import matplotlib.pyplot as plt
- import numpy as np
- import pandas as pd
- A = pd.read_csv('data_1d.csv', header=None).as_matrix()
- x = A[:,0]
- y = A[:,1]
- plt.scatter(x, y)
- x_line = np.linspace(0, 100, 100)
- y_line = 2*x_line + 1
- plt.plot(x_line, y_line)
- plt.show()
Histogram
Load data from CSV file "data_1d.csv":
- test3.py
- #!/usr/bin/env python3
- import matplotlib.pyplot as plt
- import numpy as np
- import pandas as pd
- A = pd.read_csv('data_1d.csv', header=None).as_matrix()
- x = A[:,0]
- y = A[:,1]
- y_actual = 2*x + 1
- residuals = y - y_actual
- plt.hist(residuals)
- plt.show()
Plotting Images
Download train.csv for testing script below:
- test4.py
- #!/usr/bin/env python3
- import matplotlib.pyplot as plt
- import numpy as np
- import pandas as pd
- df = pd.read_csv('train.csv')
- print("Input data shape=%s" % str(df.shape))
- M = df.as_matrix()
- im = M[0, 1:] # Remove label
- im = im.reshape(28, 28)
- print("The shape of image=%s" % (str(im.shape)))
- print("The image with label=%s" % (M[0,0]))
- plt.imshow(255 - im, cmap='gray')
- plt.show()
沒有留言:
張貼留言