我想遍歷串列中稱為 ObjectID 的所有連續專案對,然后我想繪制和演示一個二維圖,該圖顯示名為 Slops 的串列中兩個特定節點/點之間的每個 slop 值。
meterBetweenTwoPoints = 5
currentPointDateTimes = []
objectHeights = []
objectIDs = []
objectsIDsForGraphNodes = []
slopeValues = []
..
for x in range(0, len(objectHeights)):
objectsIDsForGraphNodes.append(objectIDs[sortedIndexLibrarycurrentPointDateTimes[x]])
print(objectsIDsForGraphNodes)
>> [1480642, 1504454, 1504455, 1504456, 1504457, 1504458]
for x in range(0, len(objectHeights)-1):
pointXHeight = objectHeights[sortedIndexLibrarycurrentPointDateTimes[x]]
pointYHeight = objectHeights[sortedIndexLibrarycurrentPointDateTimes[x 1]]
currentSlopeValue = ((pointYHeight - pointXHeight) / meterBetweenTwoPoints) * 100
slopeValues.append(currentSlopeValue)
print(slopeValues)
>> [-14.6541400000001, -4.927820000000054, -2.8426600000000235, -2.2563800000000356, -1.0200999999997862]
因此,這意味著我有 6 個不同的節點和 5 個不同的斜率值。
如您所見,串列的大小不相等,但我可以為名為lopeValues 的串列分配一個額外的“零”。我可以將串列轉換為資料框,但仍然無法成功。
我的環境不能支持像“plotly”這樣的庫。
我準備了一個可視化來明確我的請求/需求:

此圖表示所需的輸出。我使用 matplotlib、seaborn 和 pandas 嘗試了多種解決方案,但我無法執行輸出。
除此之外,是否有更好的可視化來顯示特定點(道路)之間的傾斜度/坡度值?
提前致謝,我很感激。
uj5u.com熱心網友回復:
import matplotlib.pyplot as plt
X = [1480642, 1504454, 1504455, 1504456, 1504457, 1504458]
Y = [-14.6541400000001, -4.927820000000054, -2.8426600000000235, -2.2563800000000356, -1.0200999999997862]
#Custom X tick text
X_ticks = ['[' str(X[i]) '-' str(X[i 1]) ']' for i in range(0,len(X)-1)]
# add 0 to make list size equal
X_ticks.insert(0, 0)
Y.insert(0,0)
#Draw Plot
plt.figure(1, figsize = (12,6))
plt.suptitle('Slope Plot')
ax = plt.gca()
x_axis = range(0,len(X_ticks))
ax.set_xlim([0, len(X_ticks)])
ax.set_ylim([0, min(Y) - 2 ])
# Draw horizontal lines
for v in Y:
plt.axhline(y=v, color='g', linestyle='--')
plt.xticks(x_axis, X_ticks)
plt.yticks(Y)
plt.plot(x_axis, Y, 'ro--')
這是情節:-

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/359791.html
標籤:Python 熊猫 数据框 matplotlib 海生
