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

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

twinx 網(wǎng)格線的可見性

twinx 網(wǎng)格線的可見性

尚方寶劍之說 2021-12-17 16:33:02
使用 來(lái)創(chuàng)建具有兩個(gè)不同高度比例的重疊條形圖時(shí)Axes.twinx(),我無(wú)法將“雙”軸集的垂直網(wǎng)格線設(shè)置為可見。水平線雖然工作正常。關(guān)于如何解決這個(gè)問題的任何想法?下面是一些示例代碼,說明了我想做什么和我不能做什么。正如所見,垂直網(wǎng)格線被 的紅色條隱藏ax2,而我希望網(wǎng)格線通過所有條可見。# Create figure and figure layoutax1 = plt.subplot()ax2 = ax1.twinx()# Example datax = [0, 1, 2, 3, 4, 5]h1 = [55, 63, 70, 84, 73, 93]h2 = [4, 5, 4, 7, 4, 3]# Plot barsh1_bars = ax1.bar(x, h1, width=0.6, color='darkblue')h2_bars = ax2.bar(x, h2, width=0.6, color='darkred')# Set y limits and grid visibilityfor ax, ylim in zip([ax1, ax2], [100, 10]):    ax.set_ylim(0, ylim)    ax.grid(True)出現(xiàn)錯(cuò)誤是因?yàn)?的垂直網(wǎng)格線ax2未設(shè)置為可見。這可以通過設(shè)置來(lái)測(cè)試ax1.grid(False),在這種情況下,只有水平網(wǎng)格線。我已經(jīng)試過的所有組合ax1.xaxis.grid(True),ax1.yaxis.grid(True),ax2.xaxis.grid(True)并ax2.yaxis.grid(True)沒有任何的運(yùn)氣。對(duì)此事的任何幫助深表感謝!
查看完整描述

1 回答

?
qq_遁去的一_1

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

您可以恢復(fù) ax1 和 ax2 的角色,這樣藍(lán)色條在 ax2 上,紅色條在 ax1 上。然后您需要將雙軸放在背景中,并在圖的另一側(cè)勾選相應(yīng)的 y 軸。


import matplotlib.pyplot as plt


# Create figure and figure layout

ax1 = plt.subplot()

ax2 = ax1.twinx()


# Example data

x = [0, 1, 2, 3, 4, 5]

h1 = [55, 63, 70, 84, 73, 93]

h2 = [4, 5, 4, 7, 4, 3]


# Plot bars

h1_bars = ax2.bar(x, h1, width=0.6, color='darkblue')

h2_bars = ax1.bar(x, h2, width=0.6, color='darkred')


# Set y limits and grid visibility

for ax, ylim in zip([ax1, ax2], [10, 100]):

    ax.set_ylim(0, ylim)

    ax.grid(True)



ax1.set_zorder(1)

ax1.patch.set_alpha(0)

ax2.set_zorder(0)


ax1.yaxis.tick_right()

ax2.yaxis.tick_left()


plt.show()

http://img1.sycdn.imooc.com//61bc4b6f0001552e06010430.jpg

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

添加回答

舉報(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)