【亲测有效】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()以及为图片名编号:


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

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




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

相关推荐
CYRUS_STUDIO17 小时前
用 Frida 控制 Android 线程:kill 命令、挂起与恢复全解析
android·linux·逆向
熊猫李18 小时前
rootfs-根文件系统详解
linux
dessler21 小时前
Hadoop HDFS-高可用集群部署
linux·运维·hdfs
泽泽爱旅行21 小时前
awk 语法解析-前端学习
linux·前端
轻松Ai享生活2 天前
5 节课深入学习Linux Cgroups
linux
christine-rr2 天前
linux常用命令(4)——压缩命令
linux·服务器·redis
三坛海会大神5552 天前
LVS与Keepalived详解(二)LVS负载均衡实现实操
linux·负载均衡·lvs
東雪蓮☆2 天前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs
乌萨奇也要立志学C++2 天前
【Linux】进程概念(二):进程查看与 fork 初探
linux·运维·服务器
绿箭柠檬茶2 天前
Ubuntu 服务器配置转发网络访问
服务器·网络·ubuntu