Tensorflow与keras学习 (6)——python_数据绘图

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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Arthur.AI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值