步骤:
- 导包:import matplotlib.pyplot as plt / import numpy as np准备数据使用函数绘制图像plt.show()
绘图代码:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1,8)
y = np.array([1,2,3,4,5,6,7])
plt.plot(x,y)
plt.title("2020080603002")
plt.show()
In [19]:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1,13)
y1 = np.array([21,22,23,25,30,33,25,24,26,28,30,33])
y2 = np.array([28,30,31,32,33,33,23,24,33,35,36,20])
plt.plot(x,y1)
plt.plot(x,y2)
plt.title("2020080603002")
plt.show()
In [21]:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(4)
y = np.array([10,20,30,15])
bar_width = 0.4
plt.bar(x,y,width=bar_width)
plt.title("2020080603002")
plt.show()
In [25]:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(4)
y = np.array([10,20,30,15])
y1 = np.array([5,10,20,25])
bar_width = 0.4
plt.bar(x,y,width=bar_width)
plt.bar(x+bar_width,y1,width=bar_width)
plt.title("2020080603002")
plt.show()
In [27]:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(4)
y = np.array([10,20,30,15])
y1 = np.array([5,10,20,25])
bar_width = 0.4
plt.bar(x,y,width=bar_width)
plt.bar(x,y1,width=bar_width,bottom=y)
plt.title("2020080603002")
plt.show()
In [37]:
import matplotlib.pyplot as plt
import numpy as np
y2 = np.arange(5)
x2 = np.array([10,8,7,11,13])
bar_height = 0.3
plt.barh(y2,x2,height=bar_height)
plt.title("2020080603002")
plt.show()
In [41]:
import matplotlib.pyplot as plt
import numpy as np
y2 = np.arange(5)
x2 = np.array([10,8,7,11,15])
x3 = np.array([8,7,6,5,10])
bar_height = 0.3
plt.barh(y2,x2,height=bar_height)
plt.barh(y2+bar_height,x3,height=bar_height)
plt.title("2020080603002")
plt.show()
In [43]:
import matplotlib.pyplot as plt
import numpy as np
y2 = np.arange(5)
x2 = np.array([10,8,7,11,15])
x3 = np.array([8,7,6,5,10])
bar_height = 0.3
plt.barh(y2,x2,height=bar_height)
plt.barh(y2,x3,left=x2,height=bar_height)
plt.title("2020080603002")
plt.show()
import matplotlib.pyplot as plt
import numpy as np
plt.title("2020080603002")
x = np.arange(6)
y1 = np.array([1,3,5,7,9,5])
y2 = np.array([1,4,5,7,10,8])
y3 = np.array([3,2,8,7,6,4])
plt.stackplot(x,y1,y2,y2)
plt.show()
In [2]:
import matplotlib.pyplot as plt
import numpy as np
plt.title("2020080603002")
scores = np.random.randint(0, 100, 51)
plt.hist(scores, bins = 51)
plt.show()
In [18]:
import matplotlib.pyplot as plt
import numpy as np
plt.title("2020080603002")
data = np.array([10,20,31,45,55])
pie_label = (['A', 'B', 'C', 'D', 'E'])
plt.pie(data, radius = 1.5, labels = pie_label, autopct = '%3.2f%%')
plt.show()
In [20]:
import matplotlib.pyplot as plt
import numpy as np
plt.title("2020080603002")
data = np.array([10,20,35,45,55])
pie_label = (['A', 'B', 'C', 'D', 'E'])
pie_explode = [0.1, 0.1, 0.1, 0.1, 0.1]
plt.pie(data, radius = 1.5, labels = pie_label, autopct = '%3.2f%%', explode = pie_explode, shadow = True)
plt.show()
In [21]:
import matplotlib.pyplot as plt
import numpy as np
plt.title("2020080603002")
data = np.array([10,20,31,45,55])
pie_label = (['A', 'B', 'C', 'D', 'E'])
plt.pie(data, radius = 1.5, labels = pie_label, autopct = '%3.2f%%', wedgeprops = {'width': 0.7}, pctdistance = 0.8)
plt.show()
In [22]:
import matplotlib.pyplot as plt
import numpy as np
plt.title("2020080603002")
x = np.random.rand(50)
y = np.random.rand(50)
area = x * 30 + y * 30
plt.scatter(x,y, s = area)
plt.show()
In [26]:
import matplotlib.pyplot as plt
import numpy as np
plt.title("2020080603002")
data = np.random.rand(100)
plt.boxplot(data, meanline = True, widths = 0.4,vert = False )
plt.show()
In [34]:
import matplotlib.pyplot as plt
import numpy as np
plt.title("2020080603002")
plt.rcParams['font.family'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
num = 3
data = np.array([[0.5, 0.6, 0.7],
[0.4, 0.45, 0.8],
[0.2, 0.65, 0.5]])
angles = np.linspace(0, 2 * np.pi, num, endpoint = False)
angles = np.concatenate((angles, [angles[0]]))
data = np.concatenate((data, [data[0]]))
polar_lable = ['艺术', '逻辑', '想象']
polar_lable = np.concatenate((polar_lable, [polar_lable[0]]))
plt.polar(angles, data)
plt.thetagrids(angles * 180/np.pi, labels = polar_lable)
plt.fill(angles, data, alpha = 0.25)
plt.show()
C:UsersADMINI~1AppDataLocalTemp/ipykernel_7760/3312525444.py:15: UserWarning: Trying to create polar plot on an Axes that does not have a polar projection. plt.polar(angles, data)
In [40]:
import matplotlib.pyplot as plt
import numpy as np
plt.title("2020080603002")
x = np.arange(5)
y = np.array([20, 10, 5, 15, 30])
error = [3, 5, 2, 3, 3]
plt.errorbar(x, y, yerr = error, capsize = 3, capthick = 2)
plt.show()
In [6]:
import matplotlib.pyplot as plt
import numpy as np
plt.title("2020080603002")
plt.rcParams['font.family'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
x = np.arange(3)
y1 = ([2.04, 1.57, 1.63])
y2 = ([1.69, 1.61, 1.64])
y3 = ([4.65, 4.99, 4.94])
y4 = ([3.39, 2.33, 4.10])
error1 = [0.16,0.08,0.10]
error2 = [0.27,0.14,0.14]
error3 = [0.34,0.32,0.29]
error4 = [0.23,0.23,0.39]
bar_width = 0.3
plt.bar(x, y1, bar_width)
plt.bar(x + bar_width, y2, bar_width, align = 'center', tick_label =["春季", "夏季", "秋季"])
plt.bar(x + 2*bar_width, y3, bar_width)
plt.bar(x + 3*bar_width, y4, bar_width)
plt.errorbar(x, y1, yerr = error1, capsize = 3, elinewidth = 2, fmt = 'k,' )
plt.errorbar(x + bar_width, y2, yerr = error2, capsize = 3, elinewidth = 2, fmt = 'k,' )
plt.errorbar(x + 2*bar_width, y3, yerr = error3, capsize = 3, elinewidth = 2, fmt = 'k,' )
plt.errorbar(x + 3*bar_width, y4, yerr = error4, capsize = 3, elinewidth = 2, fmt = 'k,' )
plt.show()
In [ ]:



