1,在python中显示图像可以用cv2, PIL.image ,要想像matlab中一样显示数据要用matplotlib模块
注:开始调用matplotlib出错,显示无qt插件,
matplotlib.getbackend()
显示:Qt5agg ,卸载重装后显示:Tkagg, 调用显示正常
import
numpy
as
np
import
matplotlib.pyplot
as
plt
x
=
np
.
arange(
0
,
5
,
0.1
);y
=
np
.
sin(x)plt
.
plot(x, y)
plt. annotate(s, xy = arrow_crd, xytext = text_crd, arrowprops = dict)
: 在图形中增加带箭头的注解。s表示要注解的字符串是什么,xy对应箭头所在的位置,xytext对应文本所在位置,arrowprops定义显示的属性
plt.plot(x,y , fmt) :绘制坐标图
plt.boxplot(data, notch, position): 绘制箱形图
plt.bar(left, height, width, bottom) : 绘制条形图
plt.barh(width, bottom, left, height) : 绘制横向条形图
plt.polar(theta, r) : 绘制极坐标图
plt.pie(data, explode) : 绘制饼图
plt.scatter(x, y) :绘制散点图
plt.hist(x, bings, normed) : 绘制直方图
2,分析程序如下:
labels = (
"bus"
,
"dinosaurs"
,
"flower"
,
"horse"
)
def
plot_preds(image, preds,labels):
"""Displays image and the top-n predicted probabilities in a bar graph
"""
plt.imshow(image)
plt.axis(
'off'
)
plt.figure()
#分图显示
plt.barh([
0
,
1
,
2
,
3
,
4
], preds,
alpha
=
0.5
)
#横条状图,索引,数值,显示的透明度
plt.yticks([
0
,
1
,
2
,
3
,
4
], labels)
# y轴加标签
plt.xlabel(
'Probability'
)
#x轴加标签
# plt.xlim(0,1.01)
# plt.tight_layout()
plt.show()