当前位置:网站首页>pychrm社区版调用matplotlib.pyplot.imshow()函数图像不弹出的解决方法
pychrm社区版调用matplotlib.pyplot.imshow()函数图像不弹出的解决方法
2022-07-06 11:02:00 【--吉择--】
前言
学习吴恩达老师的deeplearningai课程,完成第二周编程作业二,想自己在pycharm中重新写一遍代码,发现加载完数据集后图像不显示。
环境
win10
anaconda3
python3.8
pychrm-community-2022.1.3
解决方法
方法一:
导入pylab库(pylab是matplotlib中的一个模块,直接导入即可。)
在plt.imshow(train_set_x_orig[index])后加一句pylab.show()
import numpy as np
from matplotlib import pyplot as plt
import h5py
import scipy
from PIL import Image
from scipy import ndimage
import scipy.misc
import pylab
def load_dataset():
train_dataset = h5py.File('datasets/train_catvnoncat.h5', "r")
train_set_x_orig = np.array(train_dataset["train_set_x"][:]) # your train set features
train_set_y_orig = np.array(train_dataset["train_set_y"][:]) # your train set labels
test_dataset = h5py.File('datasets/test_catvnoncat.h5', "r")
test_set_x_orig = np.array(test_dataset["test_set_x"][:]) # your test set features
test_set_y_orig = np.array(test_dataset["test_set_y"][:]) # your test set labels
classes = np.array(test_dataset["list_classes"][:]) # the list of classes
train_set_y_orig = train_set_y_orig.reshape((1, train_set_y_orig.shape[0]))
test_set_y_orig = test_set_y_orig.reshape((1, test_set_y_orig.shape[0]))
return train_set_x_orig, train_set_y_orig, test_set_x_orig, test_set_y_orig, classes
train_set_x_orig, train_set_y, test_set_x_orig, test_set_y, classes = load_dataset()
index = 5
plt.imshow(train_set_x_orig[index])
pylab.show()
print("y = " + str(train_set_y[:, index]) + ", it's a '" + classes[np.squeeze(train_set_y[:, index])].decode(
"utf-8") + "' picture.")
方法二:
在plt.imshow(train_set_x_orig[index])后加一句plt.show()
PS
- 网上有中解决方法是pycharm–>File | Settings | Tools | Python Scientific | 取消勾选Show plots in tool window,但我的pycharm里根本没有Python Scientific这个选项
- pycharm使用plt不显示图片解决方案
这篇博客解释了为什么在jupyter中可以显示而pycharm中不可以显示。 - 感觉中科大的镜像源蛮好用
pip3 install -i https://pypi.mirrors.ustc.edu.cn/simple/ pylab
边栏推荐
- Implementation of AVL tree
- 【LeetCode第 300 场周赛】
- Using block to realize the traditional values between two pages
- Describe the process of key exchange
- AvL树的实现
- Cobra quick start - designed for command line programs
- Test 123
- Collection of penetration test information -- use with nmap and other tools
- Crawling data encounters single point login problem
- Summary of performance knowledge points
猜你喜欢
287. Find duplicates
Openmv4 learning notes 1 --- one click download, background knowledge of image processing, lab brightness contrast
Jushan database was among the first batch of financial information innovation solutions!
【LeetCode第 300 场周赛】
Docker安装Redis
C#/VB. Net to add text / image watermarks to PDF documents
From 2022 to 2024, the list of cifar azrieli global scholars was announced, and 18 young scholars joined 6 research projects
【中山大学】考研初试复试资料分享
Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
能源行业的数字化“新”运维
随机推荐
Atcoder a mountaineer
Test 1234
AFNetworking框架_上传文件或图像server
Use map function and split function to type multiple elements in one line
视频化全链路智能上云?一文详解什么是阿里云视频云「智能媒体生产」
二叉搜索树
Interpreting cloud native technology
Installation and management procedures
华为0基金会——图片整理
美庐生物IPO被终止:年营收3.85亿 陈林为实控人
Oracle advanced (IV) table connection explanation
[the 300th weekly match of leetcode]
爬虫玩得好,牢饭吃到饱?这3条底线千万不能碰!
一种用于夜间和无袖测量血压手臂可穿戴设备【翻译】
[Matlab] Simulink 同一模块的输入输出的变量不能同名
POJ 2208 已知边四面体六个长度,计算体积
基于蝴蝶种类识别
If you have any problems, you can contact me. A rookie ~
文档编辑之markdown语法(typora)
C#/VB. Net to add text / image watermarks to PDF documents