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

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

寫兩個或三個 x 刻度標簽,使用 matplotlib 顯示 UT 和 MLT

寫兩個或三個 x 刻度標簽,使用 matplotlib 顯示 UT 和 MLT

慕的地6264312 2021-07-30 09:44:05
我正在嘗試制作這個圖,類似于所附的示例圖。我還附上了示例數據。示例數據我想繪制一列(BLC 73.61、FCC 68.5、BSL 40.69)與時間的關系圖,它們位于數據框的索引中,并與日期時間 xticks 一起繪制,并希望顯示相應的 MLT(磁性本地時間)值,即位于數據庫的第四列。這是我正在嘗試執行的代碼:圖片展示了我想做的一個例子。x 刻度標簽在一行中以日期時間格式顯示 uT 小時的值,在第二行或第三行中顯示 MLT 的對應值# read the datadata = pd.read_csv('dados.csv', index_col=[0])#plotting fig = plt.figure(figsize=(10, 5)) #ax1 = fig.add_subplot(111)ax2 = ax1.twiny() # second x-axisax1.plot(data.index,data['BLC 73.61'])ax2.xaxis.set_ticks_position("bottom")ax2.xaxis.set_label_position("bottom")ax2.spines["bottom"].set_position(("axes", -0.2))ax2.spines['bottom'].set_color('none')majorLocator   = MultipleLocator(1)minorLocator   = MultipleLocator(1)ax1.xaxis.set_major_locator(majorLocator)ax1.xaxis.set_minor_locator(minorLocator)ax1.xaxis.set_major_locator(majorLocator)ax1.xaxis.set_minor_locator(minorLocator)ax1.xaxis.set_minor_formatter(dates.DateFormatter('%H:%M'))ax1.xaxis.set_minor_locator(mdates.MinuteLocator(interval=30))ax1.xaxis.set_major_formatter(dates.DateFormatter('%H:%M\n%b %d, %Y'))ax1.xaxis.set_major_locator(mdates.HourLocator(interval=30))ax2.set_xticklabels(data['MLT'].values)# ax2.xaxis.set_minor_formatter(dates.DateFormatter('%H:%M'))# ax2.xaxis.set_minor_locator(mdates.MinuteLocator(interval=30))# ax2.xaxis.set_major_formatter(dates.DateFormatter('%H:%M\n%b %d, %Y'))# ax2.xaxis.set_major_locator(mdates.HourLocator(interval=30))a=ax2.get_xticks().tolist()這是我得到的結果:
查看完整描述

1 回答

?
holdtom

TA貢獻1805條經驗 獲得超10個贊

我剛剛為此找到了一種解決方案。


我創建了一個函數來定義我想要的刻度并使用了 FuncFormatter 模塊。


def format_func(value, tick_number):


    hora = mdates.num2date(value)

    teste = mlt['BLC 73.61'][hora]

    return ('%d:%d \n %0.1f'  % (hora.hour, hora.minute,teste))


def format_func2(value, tick_number):

    # find the first value

    if tick_number == 0:

        return ('hh:mm     \n MLT     ')

    else:

        return (' ')

首先將時間戳值轉換為數字:


xx = [mdates.date2num(i) for i in ada[ini:end].index]

和情節


fig = plt.figure(figsize=(10, 5)) #

ax1 = fig.add_subplot(111)

ax1.plot(xx,ada['BLC 73.61'][ini:end])

# set the major locator ion the month values

ax1.xaxis.set_major_locator(mdates.MonthLocator(interval=5))

# use the format difeined in format_func2

ax1.xaxis.set_major_formatter(plt.FuncFormatter(format_func2))

ax1.xaxis.set_minor_locator(mdates.HourLocator(interval=2)) 

ax1.xaxis.set_minor_formatter(plt.FuncFormatter(format_func))


查看完整回答
反對 回復 2021-08-03
  • 1 回答
  • 0 關注
  • 161 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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