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


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

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




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

相关推荐
阿猿收手吧!10 分钟前
【Linux网络】shutdown()与close()的区别
linux·网络
LCG元21 分钟前
Linux 磁盘管理从入门到精通:LVM 扩容实战案例
linux
liu****22 分钟前
12.线程(二)
linux·开发语言·c++·1024程序员节
咯哦哦哦哦26 分钟前
vscode arm交叉编译 中 cmakeTools 编译器设置
linux·arm开发·vscode·编辑器
梁正雄1 小时前
6、prometheus资源规划
运维·服务器·服务发现·prometheus·监控
晨曦之旅1 小时前
零成本体验云计算!阿贝云免费服务器深度测评
运维·服务器·云计算
工具人55551 小时前
Linux 抓取 RAM Dump 完整指南
linux·运维·安全
不懂音乐的欣赏者2 小时前
Windows 下 ROS/ROS2 开发环境最优解:WSL 比直接安装、虚拟机、双系统更优雅!
linux·windows·ubuntu·ros·wsl·ros2·双系统
神仙别闹3 小时前
基于C语言 HTTP 服务器客户端的实验
服务器·c语言·http
小狗爱吃黄桃罐头3 小时前
正点原子【第四期】Linux之驱动开发学习笔记-10.1 Linux 内核定时器实验
linux·驱动开发·学习