【问题标题】:How to save the contour plot with .png format in python如何在python中以.png格式保存等高线图
【发布时间】:2022-06-14 22:42:21
【问题描述】:

我想在 python 中保存轮廓。我不能做得很好。 我使用 plt.savefig() 但图像是空的。 为什么?

!pip install tftb
import numpy as np
import matplotlib.pyplot as plt
import scipy.io as sio
from tftb.generators import atoms
import tftb
import cv2

mat = sio.loadmat('/content/drive/MyDrive/z5_25.mat')
signal = mat['z']
z = signal.T

images_dir = '/content/drive/MyDrive/image'

for i in range(122):
wvd = tftb.processing.WignerVilleDistribution(z[i])
wvd.run()
fig = plt.figure()
plt.rcParams['figure.figsize']=(1.5,1.5)
wvd.plot(kind = 'contour')
plt.savefig(f"{images_dir}/fig5_25_{i}.png")
plt.show()

【问题讨论】:

    标签: save contour


    【解决方案1】:

    我知道现在已经很晚了,但是您可以通过在该行中将 plt 替换为 wvd 来做到这一点

    wvd.plot(kind = 'contour') plt.savefig(f"{images_dir}/fig5_25_{i}.png")

    像这样:

    wvd.plot(kind = 'contour') wvd.savefig(f"{images_dir}/fig5_25_{i}.png")

    它应该可以工作

    【讨论】:

      猜你喜欢
      • 2017-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-07
      • 1970-01-01
      • 2019-12-21
      • 2023-03-05
      相关资源
      最近更新 更多