亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Matplotlib:嘗試刪除軸,但 plt.axis('off') 將所有圖形變為透明,為什么?

Matplotlib:嘗試刪除軸,但 plt.axis('off') 將所有圖形變為透明,為什么?

泛舟湖上清波郎朗 2023-01-04 13:29:54
我嘗試使用 plt.axis('off') 刪除軸,但是當我添加此代碼時,它會將所有圖形變為透明,代碼運行沒有問題但軸沒有 plt.axis('off')。這是代碼import matplotlib as mplimport matplotlib.pyplot as pltimport numpy as npdef plot_net(line, dot, name = "test.png"):    mpl.rcParams['agg.path.chunksize'] = 10000    fig = plt.figure(figsize = (5, 5), frameon = False)    axiss = fig.add_axes([0, 0, 1, 1])    axiss.set_aspect('equal', adjustable = 'datalim')    plt.axis('off')    axiss.scatter(dot[:, 0], dot[:, 1], color = 'red', s = 4)    axiss.plot(line[:, 0], line[:, 1], 'r.', ls = '-', color = '#0063ba', markersize = 2)    plt.savefig(name, bbox_inches = 'tight', pad_inches = 0, dpi = 200)    plt.close()a = np.random.rand(4, 2)b = np.random.rand(4, 2)plot_net(a, b, name = "test2.png")沒有 plt.axis('off') 的結果 enter image description hereplt.axis('off') 的結果 enter image description here
查看完整描述

2 回答

?
陪伴而非守候

TA貢獻1757條經驗 獲得超8個贊

嘗試將可見性設置為 false 而不是使用“off”:


import matplotlib as mpl

import matplotlib.pyplot as plt


import numpy as np


def plot_net(line, dot, name = "test.png"):

    mpl.rcParams['agg.path.chunksize'] = 10000


    fig = plt.figure(figsize = (5, 5), frameon = False)

    axiss = fig.add_axes([0, 0, 1, 1])


    axiss.set_aspect('equal', adjustable = 'datalim')


    axiss.get_yaxis().set_visible(False)

    axiss.get_xaxis().set_visible(False)


    axiss.scatter(dot[:, 0], dot[:, 1], color = 'red', s = 4)

    axiss.plot(line[:, 0], line[:, 1], 'r.', ls = '-', color = '#0063ba', markersize = 2)


    plt.savefig(name, bbox_inches = 'tight', pad_inches = 0, dpi = 200)

    plt.close()


a = np.random.rand(4, 2)

b = np.random.rand(4, 2)


plot_net(a, b, name = "c:/temp/test2.png")


查看完整回答
反對 回復 2023-01-04
?
慕虎7371278

TA貢獻1802條經驗 獲得超4個贊

我剛剛在https://repl.it/repls/DentalRunnyBlockchain#test.png上試過你的代碼

它工作正常所以 axis off 做你想實現的


查看完整回答
反對 回復 2023-01-04
?
當年話下

TA貢獻1890條經驗 獲得超9個贊

看起來它與您對“軸”的定義有關。如果你繞過它它會起作用:


import matplotlib as mpl

import matplotlib.pyplot as plt


import numpy as np


def plot_net(line, dot, name = "test.png"):

    mpl.rcParams['agg.path.chunksize'] = 10000


    fig = plt.figure(figsize = (5, 5), frameon = False)


    plt.axes().set_aspect('equal', adjustable = 'datalim')


    plt.scatter(dot[:, 0], dot[:, 1], color = 'red', s = 4)

    plt.plot(line[:, 0], line[:, 1], 'r.', ls = '-', color = '#0063ba', markersize = 2)


    plt.axis('off')


    plt.savefig(name, bbox_inches = 'tight', pad_inches = 0, dpi = 200)

    plt.close()


a = np.random.rand(4, 2)

b = np.random.rand(4, 2)


plot_net(a, b)


查看完整回答
反對 回復 2023-01-04
  • 2 回答
  • 0 關注
  • 272 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號