![](/img/trans.png)
[英]How can I make the origin of the x-axis and the origin of the y-axis of a plot overlap in matplotlib?
[英]How can I plot the figure with the number of pixel as a x-axis and the grayscale color as a y-axis in python?
我下載了 MNIST 數據集和 plot 數據集的第一張圖像,其中 imshow function 是灰度的。 這是我的代碼。
import numpy as np
import matplotlib.pyplot as plt
import torch
import torchvision
from torchvision import transforms
# MNIST dataset
transform = transforms.Compose([transforms.ToTensor()])
train_dataset = torchvision.datasets.MNIST(root='./data',
train=True,
download=True,
transform=transform)
# Change data type : torch.Tensor -> numpy array
X = train_dataset.train_data.numpy()
y = train_dataset.train_labels.numpy()
print('Data size: ' + str(X.shape))
num_samples, height, width = X.shape
dim = height * width
# Visualize MNIST data (1st digit)
plt.figure(1)
plt.imshow(X[0],cmap='gray_r')
plt.colorbar()
plt.title('1st image label: 5')
我得到了這個數字
將二維圖像向量重塑為一維向量后,我想將 plot 變成這樣的圖。
x 軸表示像素數,y 軸表示其像素值作為灰度顏色,plot 就是這樣,光譜之類的。 我知道如何重塑矢量,但我不知道如何制作 plot。 我可以在 matplotlib 模塊中使用 function 使 plot 像第二個一樣嗎? 還是在某個地方?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.