@@ -2153,7 +2153,7 @@ def updatePositions(self):
21532153 platform .r [1 ] = platform .body .r6 [1 ]
21542154
21552155
2156- def plot2d (self , ax = None , plot_seabed = False ,draw_soil = False ,plot_bathymetry = True , plot_boundary = True , bare = False , axis_equal = True ,save = False ,** kwargs ):
2156+ def plot2d (self , ax = None , plot_seabed = False ,draw_soil = False ,plot_bathymetry = True , plot_boundary = True , color_lineDepth = False , bare = False , axis_equal = True ,save = False ,** kwargs ):
21572157 '''Plot aspects of the Project object in matplotlib in 3D.
21582158
21592159 TODO - harmonize a lot of the seabed stuff with MoorPy System.plot...
@@ -2163,6 +2163,8 @@ def plot2d(self, ax=None, plot_seabed=False,draw_soil=False,plot_bathymetry=True
21632163 ...
21642164 bare : bool
21652165 If True, supress display of extra labeling like the colorbar.
2166+ color_lineDepth: bool
2167+ If True, color mooring lines based on depth. Only works if plot_bathymetry=False.
21662168 '''
21672169
21682170 # Handle extra keyword arguments or use default values
@@ -2182,7 +2184,8 @@ def plot2d(self, ax=None, plot_seabed=False,draw_soil=False,plot_bathymetry=True
21822184 bath_levels = kwargs .get ('bath_levels' , None )
21832185 show_legend = kwargs .get ('show_legend' , True )
21842186
2185-
2187+ max_line_depth = kwargs .get ('max_line_depth' , None ) # max depth for line coloring if color_lineDepth is True
2188+ only_shared = kwargs .get ('only_shared' , False ) # if color_lineDepth is True, only color shared lines
21862189 # if axes not passed in, make a new figure
21872190 if ax == None :
21882191 fig , ax = plt .subplots (1 ,1 , figsize = figsize )
@@ -2250,6 +2253,16 @@ def plot2d(self, ax=None, plot_seabed=False,draw_soil=False,plot_bathymetry=True
22502253 ax .fill (env ['x' ], env ['y' ], edgecolor = edgecolor , facecolor = 'none' , linestyle = 'dashed' , lw = 0.8 , label = 'Platform Envelope' )
22512254
22522255 if plot_moorings :
2256+ line_depth_settings = None
2257+ if color_lineDepth :
2258+ if plot_bathymetry :
2259+ raise ValueError ("Cannot use depth-based line coloring with plot_bathymetry=True. Disable bathymetry to avoid confusion." )
2260+ line_depth_settings = {
2261+ "cmap" : "Blues" ,
2262+ "vmin" : max_line_depth if max_line_depth else - np .max (self .grid_depth ),
2263+ "vmax" : 0 ,
2264+ "only_shared" : only_shared
2265+ }
22532266 for mooring in self .mooringList .values ():
22542267 for name , env in mooring .envelopes .items ():
22552268 #if 'shape' in env: # if there's a shapely object
@@ -2284,16 +2297,27 @@ def plot2d(self, ax=None, plot_seabed=False,draw_soil=False,plot_bathymetry=True
22842297
22852298 if mooring .ss :
22862299 mooring .ss .drawLine2d (0 , ax , color = "self" , endpoints = False ,
2287- Xuvec = [1 ,0 ,0 ], Yuvec = [0 ,1 ,0 ],label = labs )
2300+ Xuvec = [1 ,0 ,0 ], Yuvec = [0 ,1 ,0 ], line_depth_settings = line_depth_settings , label = labs )
22882301 elif mooring .parallels :
22892302 for i ,line in enumerate (lineList ):
22902303 line .drawLine2d (0 , ax , color = "self" ,
2291- Xuvec = [1 ,0 ,0 ], Yuvec = [0 ,1 ,0 ],label = labs [i ])
2304+ Xuvec = [1 ,0 ,0 ], Yuvec = [0 ,1 ,0 ], line_depth_settings = line_depth_settings , label = labs [i ])
22922305
22932306 else : # simple line plot
22942307 ax .plot ([mooring .rA [0 ], mooring .rB [0 ]],
22952308 [mooring .rA [1 ], mooring .rB [1 ]], 'k' , lw = 0.5 , label = 'Mooring Line' )
2296-
2309+
2310+ # ---- Add colorbar for line depth ----
2311+ if line_depth_settings is not None and not bare :
2312+ import matplotlib .cm as cm
2313+ import matplotlib .colors as mcolors
2314+ sm = cm .ScalarMappable (cmap = cm .get_cmap (line_depth_settings ["cmap" ]),
2315+ norm = mcolors .Normalize (vmin = line_depth_settings ["vmin" ],
2316+ vmax = line_depth_settings ["vmax" ]))
2317+ sm .set_array ([])
2318+ cbar = plt .colorbar (sm , ax = ax , fraction = 0.04 )
2319+ cbar .set_label ("Line Depth (m)" )
2320+
22972321 if plot_anchors :
22982322 for anchor in self .anchorList .values ():
22992323 ax .plot (anchor .r [0 ],anchor .r [1 ], 'mo' ,ms = 2 , label = 'Anchor' )
0 commit comments