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

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

如何移動第二個x軸的位置?

如何移動第二個x軸的位置?

哆啦的時光機(jī) 2023-07-11 16:29:16
我正在嘗試創(chuàng)建一個帶有輔助 x 軸的圖表,但我希望輔助 x 軸的標(biāo)簽和刻度位于第一個 x 軸下方。我目前只找到了將其移動到底部的方法,而不是移動到確切位置的方法。我附上了我想要實(shí)現(xiàn)的目標(biāo)的圖片。y = [3, 5, 2, 8, 7]x = [[10, 11, 12, 13, 14], [36, 39.6, 43.2, 46.8, 50.4]]labels = ['m/s', 'km/hr']fig,ax = plt.subplots()ax.plot(x[0], y)ax.set_xlabel("Velocity m/s")ax.set_ylabel("Time /mins")ax2=ax.twiny()ax2.plot(x[1], y)ax2.set_xlabel("Velocity km/hr")plt.show()
查看完整描述

1 回答

?
喵喔喔

TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個贊

回答

首先,您必須包含所需的庫:


import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid1 import host_subplot

import mpl_toolkits.axisartist as AA

然后你可以生成第一個軸


ax = host_subplot(111, axes_class = AA.Axes, figure = fig)

然后通過生成次軸


ax2=ax.twiny()

此時,您需要為次軸騰出一些空間,因此您應(yīng)該使用以下命令抬高繪圖區(qū)域的底部


plt.subplots_adjust(bottom = 0.2)

最后將次軸定位在第一個軸下方


offset = -40

new_fixed_axis = ax2.get_grid_helper().new_fixed_axis

ax2.axis['bottom'] = new_fixed_axis(loc = 'bottom',

                                    axes = ax2,

                                    offset = (0, offset))

ax2.axis['bottom'].toggle(all = True)

完整代碼

import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid1 import host_subplot

import mpl_toolkits.axisartist as AA


y = [3, 5, 2, 8, 7]

x = [[10, 11, 12, 13, 14], [36, 39.6, 43.2, 46.8, 50.4]]

labels = ['m/s', 'km/hr']


fig = plt.figure()

# generate the first axis

ax = host_subplot(111, axes_class = AA.Axes, figure = fig)

ax.plot(x[0], y)

ax.set_xlabel("Velocity m/s")

ax.set_ylabel("Time /mins")


ax2=ax.twiny()


# make space for the secondary axis

plt.subplots_adjust(bottom = 0.2)


# set position ax2 axis

offset = -40

new_fixed_axis = ax2.get_grid_helper().new_fixed_axis

ax2.axis['bottom'] = new_fixed_axis(loc = 'bottom',

                                    axes = ax2,

                                    offset = (0, offset))

ax2.axis['bottom'].toggle(all = True)


ax2.plot(x[1], y)

ax2.set_xlabel("Velocity km/hr")

plt.show()

結(jié)果

http://img1.sycdn.imooc.com//64ad135600010d8c05750452.jpg

查看完整回答
反對 回復(fù) 2023-07-11
  • 1 回答
  • 0 關(guān)注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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