1from matplotlib import pyplot as plt
2plt.plot([0, 1, 2, 3, 4, 5], [0, 1, 4, 9, 16, 25])
3plt.show()
1import matplotlib.pyplot as plt
2fig = plt.figure(1) #identifies the figure
3plt.title("Y vs X", fontsize='16') #title
4plt.plot([1, 2, 3, 4], [6,2,8,4]) #plot the points
5plt.xlabel("X",fontsize='13') #adds a label in the x axis
6plt.ylabel("Y",fontsize='13') #adds a label in the y axis
7plt.legend(('YvsX'),loc='best') #creates a legend to identify the plot
8plt.savefig('Y_X.png') #saves the figure in the present directory
9plt.grid() #shows a grid under the plot
10plt.show()
1import matplotlib.pyplot as plt
2plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
3plt.show()
1import matplotlib.pyplot as plt
2plt.plot([1, 2, 3, 4])
3plt.ylabel('some numbers')
4plt.show()
5
1import numpy as np
2import pandas as pd
3import matplotlib.pyplot as plt
4
5df = pd.read_csv("filesc/file1.csv")
6df.head()
7
8BBox = ((df.x.min(), df.x.max(), df.y.min(), df.y.max()))
9
10ruh_m = plt.imread('map.png')
11
12print(BBox)
13
14fig, ax = plt.subplots(figsize = (8,7))
15ax.scatter(df.x, df.y, zorder=1, alpha= 0.2, c='b', s=10)
16ax.set_title('Plotting Spatial Data on Map')
17ax.set_xlim(BBox[0],BBox[1])
18ax.set_ylim(BBox[2],BBox[3])
19ax.imshow(ruh_m, zorder=0, extent = BBox, aspect= 'equal')
20plt.show()
21
22
1import numpy as np
2import matplotlib.pyplot as plt
3
4fig = plt.figure()
5ax1 = fig.add_axes((0.1,0.4,0.5,0.5))
6
7ax1.set_title('Title of Plot')
8ax1.set_xlabel('X')
9ax1.set_ylabel('Y')
10
11ax1.plot(X,Y,c='black',linestyle='--',linewidth=0.5)
12ax1.scatter(X,Y,c='red',s=0.5)
13ax1.legend(['Line','Scatter'])
14
15ax1.xaxis.set_ticks([0.0,0.1,0.2,0.3])
16ax1.yaxis.set_ticks([0.0,0.1,0.2,0.3])
17
18ax1.grid(which='major')
19ax1.tick_params(direction='in')
20
21txt = 'Write something on the graph page\
22 \n over one or more lines.'
23
24fig.text(0.5,0.05,txt,ha='center')
25
26fig.savefig('Figure.pdf')