[英](python) Adding a colorbar by the dates of points in a 3D scatter plot with matplotlib
[英]3D scatter plot with in Python extracted from Dates
有沒有辦法可以將天轉換為字符串而不是十進制值? 對於月份也是如此。
注意:我已經訪問過這個( 3D Scatterplot with strings in Python )答案,它不能解決我的問題。
我正在做一個自我項目,我試圖從我從谷歌活動中檢索到的數據中為我的通勤創建 3D 圖表。 作為參考,我正在關注本指南: https://nvbn.github.io/2018/05/01/commute/
我能夠根據月 + 時間和日 + 時間屬性創建信息豐富的 2D 圖表,但是我希望將這 2 個圖表結合起來。
我要創建的 3D 圖表需要 3 個屬性Day (Mon/Tue), Month (Jan/Feb), Time taken 。
鑒於 matplotlib 立即不支持圖表中的字符串值,我已將數字用於日 (0-7) 和月 (1-12)。 但是,對於幾天的十進制值,圖表似乎有點模糊。 看起來像以下
我當前的代碼看起來像這樣,檢索weekday()
以獲取天數,並month
獲取。
# How commute is calculated and grouped
import pandas as pd
#{...}
def get_commute_to_work():
#{...}
yield Commute_to_work(pd.to_datetime(start.datetime), start.datetime, end.datetime, end.datetime - start.datetime)
#Now creating graph here
fig, ax = pyplot.subplots(subplot_kw={'projection': '3d'})
ax.grid()
ax.scatter([commute.day.weekday() for commute in normalised],
[commute.day.month for commute in normalised],
[commute.took.total_seconds() / 60 for commute in normalised])
ax.set(xlabel='Day',ylabel='Month' ,zlabel='commute (minutes)',
title='Daily commute')
ax.legend()
pyplot.show()
注意。 如果您想查看此代碼的詳細信息,請在此處的github上找到
你可以試試這個(雖然我還沒有驗證 3d plot):
x_tick_labels = ['Sun','Mon','Tue','Wed','Thurs', 'Fri', 'Sat']
# Set number of ticks for x-axis
x = np.linspace(1.0, 4.0, 7) # Why you have 9 days in a week is beyond me
ax.set_xticks(x)
# Set ticks labels for x-axis
ax.set_xticklabels(x_ticks_labels, rotation='vertical', fontsize=18)
您可以重復類似的程序數月。
這個答案的來源是here 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.