使用matplotlib绘制简单图表:
1,使用plot()绘制折线图:
# _maximum_minimum_temperatures
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(4,19)
y_max = np.array([32,33,34,34,33,31,30,29,30,29,26,23,21,25,31])
y_min = np.array([19,19,20,22,22,21,16,18,18,17,14,15,16,16,16])
plt.plot(x,y_max)
plt.plot(x,y_min)
plt.title("41")
plt.show()
文章图片
2,使用bar()绘制柱形图或堆积柱形图:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(5)
y1 = np.array([10,8,7,11,13])
bar_width = 0.3
plt.bar(x,y1,tick_label=['a','b','c','d','e'], width=bar_width)
plt.title("41")
plt.show()
文章图片
x = np.arange(5)
y1 = np.array([10,8,7,11,13])
y2 = np.array([9,6,5,10,12])
bar_width = 0.3
plt.bar(x,y1,tick_label=['a','b','c','d','e'], width=bar_width)
plt.bar(x,y2,bottom=y1, width=bar_width)
plt.title("41")
plt.show()
文章图片
3,使用barh()绘制条形图或堆积条形图:
import matplotlib.pyplot as plt
import numpy as np
y = np.arange(5)
x1 = np.array([10,8,7,11,13])
bar_height=0.3
plt.barh(y,x1,tick_label=['a','b','c','d','e'], height=bar_height)
plt.title("41")
plt.show()
文章图片
y = np.arange(5)
x1 = np.array([10,8,7,11,13])
x2 = np.array([9,7,6,10,12])
bar_height=0.3
plt.barh(y,x1,tick_label=['a','b','c','d','e'], height=bar_height)
plt.barh(y+bar_height,x2,height=bar_height)
plt.title("41")
plt.show()
文章图片
4,使用stackplot绘制堆积面积图:
import numpy as np
import matplotlib.pyplot as plt
x=np.arange(6)
y1= np.array([1,4,3,5,6,7])
y2=np.array([1,3,4,2,7,6])
y3=np.array([3,4,3,6,5,5])
plt.stackplot(x,y1,y2,y3)
plt.title("41")
plt.show()
文章图片
5,使用hist()绘制直方图:
scores=np.random.randint(0,100,50)
plt.hist(scores,bins=8,histtype='stepfilled')
plt.title('41')
plt.show()
文章图片
6,使用pie()绘制饼图或圆环图:
data =https://www.it610.com/article/np.array([20,50,10,15,30,55])
pie_labels=np.array(['A','B','C','D','E','F'])
plt.pie(data,radius=1.5,labels=pie_labels,autopct='%3.1f%%')
plt.title('41')
plt.show()
【笔记|使用matplotlib绘制简单图表】
文章图片
data =https://www.it610.com/article/np.array([20,50,10,15,30,55])
pie_labels=np.array(['A','B','C','D','E','F'])
plt.pie(data,radius=1.5,wedgeprops={'width': 0.7},labels=pie_labels,autopct='%3.1f%%',pctdistance=0.75)
plt.title('41')
plt.show()
文章图片
7,使用scatter()绘制散点图或气泡图:
num=50
x=np.random.rand(num)
y=np.random.rand(num)
plt.title('41')
plt.scatter(x,y)
文章图片
num=50
x=np.random.rand(num)
y=np.random.rand(num)
area=(30*np.random.rand(num))**2
plt.title('41')
plt.scatter(x,y,s=area)
文章图片
8,使用boxplot()绘制箱型图:
data =https://www.it610.com/article/np.random.randn(100)
plt.boxplot(data,meanline=True,widths=0.3,patch_artist=True,showfliers=False)
plt.title('41')
plt.show()
文章图片
9,使用polar()绘制 雷达图:
plt.rcParams['font.family']= 'SimHei'
plt.rcParams['axes.unicode_minus']=False
dim_num=6
data=https://www.it610.com/article/np.array([[0.40,0.32,0.35,0.30,0.30,0.88],
[0.85,0.35,0.30,0.40,0.40,0.30],
[0.43,0.89,0.30,0.28,0.22,0.30],
[0.30,0.25,0.48,0.85,0.45,0.40],
[0.20,0.38,0.87,0.45,0.32,0.28],
[0.34,0.31,0.38,0.40,0.92,0.28]])
angles=np.linspace(0, 2 * np.pi, dim_num, endpoint=False)
angles=np.concatenate((angles,[angles[0]]))
data=np.concatenate((data,[data[0]]))
radar_labels=['研究型(I)','艺术型(A)','社会型(S)','企业型(E)','传统型(C)','现实型(R)']
radar_labels=np.concatenate((radar_labels, [radar_labels[0]]))
plt.polar(angles, data)
plt.thetagrids(angles * 180/np.pi, labels=radar_labels)
plt.fill(angles, data, alpha=0.25)
plt.title('41')
plt.show()
文章图片
推荐阅读
- 笔记|java图形用户界面编辑常用组件和容器
- 笔记|java中使用while计算1到100之间的奇数和
- 笔记|JDBC(一)
- 笔记|DBUtil工具
- 笔记|java中使用if...else来判断学生成绩等级
- 笔记|数据库连接池
- 笔记|java中使用for循环计算1到100之间的偶数和
- linux|可替代TeamView的免费远程控制软件ToDesk
- python 生产消费案例1