如何基于两个因素为散点图的颜色定义条件语句?

问题描述 投票:0回答:1

本周,我从Python和Dash开始,因为我渴望同时学习两者。

我的目标:我想挑出传感器检测到的某些点,并在它们满足两个条件的情况下为它们<上色:

    如果在上午01:00-05:00之间检测到它们,则>]
  • 并且如果在某个区域中检测到它们(假设我有一个列表每个区域的风险概率)。因此,它也应该考虑大于0.6的任何风险。

  • 着色的预期条件:

  • 如果x> 1 AND x <5 AND风险[i
    0.6 THEN颜色=红色,ELSE listCoords.index.hour

    我的问题:我的代码的color=np.append(np.insert(listCoords.index.hour, 0, 0), 23)部分必须如何更改才能达到我的目标?我在想一些类似的事情(尚不包括风险清单):color=np.where(np.logical_and(listCoords.index.hour >= 1, listCoords.index.hour <= 5), np.append(np.insert(listCoords.index.hour, 0, 0), 23), 'red')

    但是这不起作用。非常感谢您的帮助。

    我的代码段:地理地图上的点分散:

    return go.Figure( data=[ # Data for all observations based on date/time Scattermapbox( lat=listCoords["Lat"], lon=listCoords["Lon"], mode="markers", hoverinfo="text + lat + lon", text=listCoords.index.hour, marker=dict( showscale=True, color=np.append(np.insert(listCoords.index.hour, 0, 0), 23), opacity=0.5, size=5, colorscale=[ [0, "#F4EC15"], [0.04167, "#DAF017"], [0.0833, "#BBEC19"], [0.125, "#9DE81B"], [0.1667, "#80E41D"], [0.2083, "#66E01F"], [0.25, "#4CDC20"], [0.292, "#34D822"], [0.333, "#24D249"], [0.375, "#25D042"], [0.4167, "#26CC58"], [0.4583, "#28C86D"], [0.50, "#29C481"], [0.54167, "#2AC093"], [0.5833, "#2BBCA4"], [1.0, "#613099"], ], colorbar=dict( title="Time of<br>Day", x=0.93, xpad=0, nticks=24, tickfont=dict(color="#d8d8d8"), titlefont=dict(color="#d8d8d8"), thicknessmode="pixels", ), ), ),

    编辑1:提供示例数据,以便人们可以运行它:

    某些传感器检测及其日期/时间戳的列表:

    **Date/Time Lat Lon** 2019-03-25 00:05:00 -10,80948998827914 24,19160777427344 2019-03-25 00:10:00 -10,79868405083584 24,16288145431259 2019-03-25 04:05:00 -10,78688335083584 24,20288145431259 2019-03-25 04:05:00 -10,77558405083584 24,288145431259

    区域列表及其风险概率:

    ZoneRisk_Prob Zone 0 1 0 2 0,002394936420140275 3 0,030364372469635626 4 0,00005702229571762559 5 0 6 0,039345384045161656 7 0,10164224211666761 8 0,14854308034441466 9 0,0037064492216456633 10 0 11 0 12 0,0003421337743057536 13 0,1214289787306837 14 0,04410674573758339 15 0 16 0 17 0,0158236870616411 18 0 19 0,18951359981752866 20 0,0014825796886582653 21 0,0005417118093174431 22 0,027769858014483662 23 0,014027484746535895 24 0,0012259793579289502 25 0,029737127216741745 26 0,009636767976278725 27 0,060072988538518564 28 0,043051833266807324 29 0,005759251867480185 30 0,1094257854821235 31

    本周,我从Python和Dash开始,因为我渴望同时学习两者。我的目标:我想挑出传感器检测到的某些点,如果遇到两个,则将它们涂成红色...
    python conditional-statements conditional-formatting plotly-dash
    1个回答
    0
    投票
    要获得同时满足您两个要求的职位,您应该按照以下步骤进行。
    © www.soinside.com 2019 - 2024. All rights reserved.