我想迭代列表中称为ObjectID的所有连续项对,然后绘制并演示一个2D图,该图显示列表中名为Slops的两个特定节点/点之间的每个斜度值。
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个不同的坡度值。
正如您所看到的,列表的大小并不相等,但我可以将一个额外的“零”赋值给名为slopeValues的列表。我可以将列表转换为数据帧,但仍然无法实现。
我的环境不支持像"plotly“这样的库。
我准备了一个可视化工具来清楚地表达我的请求/需求:
此图表示所需的输出。我使用matplotlib、seaborn和pandas尝试了多种解决方案,但无法执行输出。
除此之外,是否有更好的可视化方法来显示特定点之间的倾斜度/坡度值(对于道路)?
提前谢谢,我很感激。
发布于 2021-11-17 00:29:55
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://stackoverflow.com/questions/70000187
复制相似问题