1import matplotlib.pyplot as plt
2plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
3plt.show()
1import matplotlib.pyplot as plt
2import numpy as np
3
4data = np.random.rand(1024,2)
5plt.scatter(data[:,0],data[:,1])
6plt.show()
7// Don't be
8// fooled by this simplicity— plt.scatter() is a rich command.
1from matplotlib import pyplot as plt
2
3# Median Developer Salaries by Age
4dev_x = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]
5
6dev_y = [38496, 42000, 46752, 49320, 53200,
7 56000, 62316, 64928, 67317, 68748, 73752]
8
9plt.plot(dev_x, dev_y)
10plt.xlabel('Ages')
11plt.ylabel('Median Salary (USD)')
12plt.title('Median Salary (USD) by Age')
13plt.show()
14
15#Basic line graph using python module matplotlib
1import plotly.express as px
2
3df = px.data.gapminder().query("continent=='Oceania'")
4fig = px.line(df, x="year", y="lifeExp", color='country')
5fig.show()
6
1import matplotlib.pyplot as plt
2fig = plt.figure()
3ax = fig.add_subplot(111)
4ax.set_xlim(0,10)
5ax.set_ylim(0,10)
6
7# draw lines
8xmin = 1
9xmax = 9
10y = 5
11height = 1
12plt.hlines(y, xmin, xmax)
13plt.vlines(xmin, y - height / 2., y + height / 2.)
14plt.vlines(xmax, y - height / 2., y + height / 2.)
15average = (xmax+xmin)/2
16
17# draw a point on the line
18px = 5
19plt.plot(px,y, 'ro', ms = 15, mfc = 'r')
20
21# add an arrow
22plt.annotate('Point', (px,y), xytext = (px+0.35, y+0.5),
23horizontalalignment='right')
24
25# add numbers
26plt.text(xmin - 0.1, y, 'Left', horizontalalignment='right')
27plt.text(xmax + 0.1, y, 'Right', horizontalalignment='left')
28
29plt.axis('off')
30plt.show()