【亲测有效】Linux/Ubuntu远程服务器使用plt.show()没有反应,vscode ssh 远程ubuntu,plt.show不显示图片问题

【亲测有效】Linux/Ubuntu远程服务器使用plt.show没有反应,vscode ssh 远程ubuntu,plt.show不显示图片问题

plt.show()在linux或者ubuntu系统中不会有显示,这是因为系统没有图形界面。

例如:

python 复制代码
		from matplotlib import pyplot as plt
        from mpl_toolkits.mplot3d import Axes3D
        from mpl_toolkits.mplot3d.art3d import Poly3DCollection

        fig = plt.figure()
        ax = fig.add_subplot(111, projection='3d')

        mesh = Poly3DCollection(vertices[model.faces], alpha=0.1)
        face_color = (1.0, 1.0, 0.9)
        edge_color = (0, 0, 0)
        mesh.set_edgecolor(edge_color)
        mesh.set_facecolor(face_color)
        ax.add_collection3d(mesh)
        ax.scatter(joints[:, 0], joints[:, 1], joints[:, 2], color='r')

        ax.view_init(azim=-90, elev=100) #  y轴朝上
        if plot_joints:
            ax.scatter(joints[:, 0], joints[:, 1], joints[:, 2], alpha=0.1)
        plt.show()
        #这里是要保存的路径/home/img_save_folder/和保存文件名Picture.png

例如,我这一段是加载我自己处理的数据时候,然后plt.show(),不可视化出我的图片。

解决方法:保存成png图片然后在程序运行后查看,如下:

只需要使用plt.savefig(savepath)。savepath为你要保存该图到哪个路径,比如下面的'./ok.png',是一个相对路径,就是将plt.show()的图片保存到当前路径下,名称为ok.png.

python 复制代码
from matplotlib import pyplot as plt
        from mpl_toolkits.mplot3d import Axes3D
        from mpl_toolkits.mplot3d.art3d import Poly3DCollection

        fig = plt.figure()
        ax = fig.add_subplot(111, projection='3d')

        mesh = Poly3DCollection(vertices[model.faces], alpha=0.1)
        face_color = (1.0, 1.0, 0.9)
        edge_color = (0, 0, 0)
        mesh.set_edgecolor(edge_color)
        mesh.set_facecolor(face_color)
        ax.add_collection3d(mesh)
        ax.scatter(joints[:, 0], joints[:, 1], joints[:, 2], color='r')

        ax.view_init(azim=-90, elev=100) #  y轴朝上
        if plot_joints:
            ax.scatter(joints[:, 0], joints[:, 1], joints[:, 2], alpha=0.1)
        plt.show()
        plt.savefig("./outputs_zzk/ok"+".png") # 保存观看
        plt.close()

如果要同时保存多个图片,为防止覆盖,可以添加plt.close()以及为图片名编号:


创作不易,观众老爷们请留步... 动起可爱的小手,点个赞再走呗 (๑◕ܫ←๑) 欢迎大家关注笔者,你的关注是我持续更博的最大动力

原创文章,转载告知,盗版必究




♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠

相关推荐
序属秋秋秋25 分钟前
《Linux系统编程之入门基础》【Linux基础 理论+命令】(下)
linux·运维·服务器·学习·ubuntu·xshell·命令
f89790707036 分钟前
配置centos 使用ssh访问文件夹
linux·centos·ssh
---学无止境---38 分钟前
Linux中VFS相关slab缓存对象的创建和初始化
linux
在路上看风景39 分钟前
3.5 面向连接的传输: TCP
服务器·tcp/ip
fxshy41 分钟前
CentOS 7上安装并配置Nginx监听81端口的完整指南
linux·nginx·centos
小熊熊知识库1 小时前
Ubuntu下载以及安装详解以及应用安装
linux·运维·ubuntu
小白银子5 小时前
零基础从头教学Linux(Day 52)
linux·运维·服务器·python·python3.11
平生不喜凡桃李7 小时前
Linux网络:UDP
linux·网络·udp
weixiao04307 小时前
Linux网络 网络层
linux·网络·智能路由器
从零开始的ops生活8 小时前
【Day 80】Linux-NAS 和 SAN 存储
linux·运维·php