第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何將 matplotlib 軸縱橫比設(shè)置為等于 twinx() 和 twiny()

如何將 matplotlib 軸縱橫比設(shè)置為等于 twinx() 和 twiny()

HUX布斯 2022-06-22 19:03:07
我正在嘗試制作一個(gè)所有四個(gè)面都有溫度標(biāo)簽的情節(jié)。我可以使用 twinx() 和 twiny() 獲得標(biāo)簽,但我無(wú)法弄清楚如何讓這些軸在縮放上相等(兩個(gè)比例上的一個(gè)單位相同,所以圖表將是長(zhǎng)方形)。import numpy as npimport matplotlib.pyplot as plt plt.style.use('classic')# Grid squares values:height = 21width = 31# Initialize matrix of zeros for that sizedata = np.zeros((height, width)) + 75# Make set temperatures on fixed positionsT_alpha   = 0    # (bottom boundary temperature)T_bravo   = 40   # (left boundary temperature)T_charlie = 100  # (top boundary temperature)T_delta   = 100  # (right boundary temperature)# Note: index 0,0 is bottom leftfor i in range(width):    data[0, i] = T_alpha    data[(height - 1), i] = T_charliefor j in range(1, (height - 1)):    data[j, 0] = T_bravo    data[j, (width - 1)] = T_delta#print(data)heatmap = plt.pcolor(data)ax = plt.axes()ax.xaxis.set_ticks_position('none')ax.yaxis.set_ticks_position('none')ax.yaxis.set_major_locator(plt.NullLocator())ax.xaxis.set_major_formatter(plt.NullFormatter())ax.set_xlabel("T = " + str(T_alpha) + "\N{DEGREE SIGN}C")ax.set_ylabel("T = " + str(T_bravo) + "\N{DEGREE SIGN}C")ax2 = ax.twinx()ax2.yaxis.set_label_position('right')ax2.yaxis.set_ticks_position('none')ax2.yaxis.set_major_locator(plt.NullLocator())ax2.set_ylabel("T = " + str(T_delta) + "\N{DEGREE SIGN}C")ax3 = ax.twiny()ax3.xaxis.set_label_position('top')ax3.xaxis.set_ticks_position('none')ax3.xaxis.set_major_formatter(plt.NullFormatter())ax3.set_xlabel("T = " + str(T_charlie) + "\N{DEGREE SIGN}C")plt.xlim(0, width)plt.ylim(0, height)cbar = plt.colorbar(heatmap)cbar.set_label("Temperature (\N{DEGREE SIGN}C)")plt.clim(0, 100)plt.show()這是我正在尋找的縮放比例(但所有四個(gè)邊都標(biāo)記了)
查看完整描述

1 回答

?
莫回?zé)o

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊

感謝@ImportanceOfBeingErnest 使用text.


這是修復(fù):


import numpy as np

import matplotlib.pyplot as plt 


plt.axes().set_aspect('equal')

plt.style.use('classic')


# Grid squares values:

height = 21

width = 31


# Initialize matrix of zeros for that size

data = np.zeros((height, width)) + 75


# Make set temperatures on fixed positions

T_alpha   = 0    # (bottom boundary temperature)

T_bravo   = 40   # (left boundary temperature)

T_charlie = 100  # (top boundary temperature)

T_delta   = 100  # (right boundary temperature)


# Note: index 0,0 is bottom left


for i in range(width):

    data[0, i] = T_alpha

    data[(height - 1), i] = T_charlie

for j in range(1, (height - 1)):

    data[j, 0] = T_bravo

    data[j, (width - 1)] = T_delta


#print(data)


heatmap = plt.pcolor(data)


plt.text(0.5, -0.02, "T = " + str(T_alpha) + "\N{DEGREE SIGN}C",

         horizontalalignment='center',

         verticalalignment='top',

         rotation=0,

         clip_on=False,

         transform=plt.gca().transAxes)

plt.text(0, 0.5, "T = " + str(T_bravo) + "\N{DEGREE SIGN}C",

         horizontalalignment='right',

         verticalalignment='center',

         rotation=90,

         clip_on=False,

         transform=plt.gca().transAxes)

plt.text(0.5, 1, "T = " + str(T_charlie) + "\N{DEGREE SIGN}C",

         horizontalalignment='center',

         verticalalignment='bottom',

         rotation=0,

         clip_on=False,

         transform=plt.gca().transAxes)

plt.text(1, 0.5, "T = " + str(T_delta) + "\N{DEGREE SIGN}C",

         horizontalalignment='left',

         verticalalignment='center',

         rotation=270,

         clip_on=False,

         transform=plt.gca().transAxes)


plt.axis("off")


plt.xlim(0, width)

plt.ylim(0, height)


cbar = plt.colorbar(heatmap)

cbar.set_label("Temperature (\N{DEGREE SIGN}C)")

plt.clim(0, 100)


plt.show()

這使


查看完整回答
反對(duì) 回復(fù) 2022-06-22
  • 1 回答
  • 0 關(guān)注
  • 191 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)