Skip to content

Commit

Permalink
Adding linewidth functionality to plot2d (#18)
Browse files Browse the repository at this point in the history
This commit adds an optional linewidth argument to System.plot2d.

Adding linewidth as a kwargs in plot2d. The function "drawLine2d" was updated to read the linewidth value.
  • Loading branch information
MYMahfouz authored Jul 12, 2024
1 parent 2364ec3 commit 059fad9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions moorpy/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def getCoordinate(self, s, n=100):



def drawLine2d(self, Time, ax, color="k", Xuvec=[1,0,0], Yuvec=[0,0,1], Xoff=0, Yoff=0, colortension=False, cmap='rainbow', plotnodes=[], plotnodesline=[], label="", alpha=1.0):
def drawLine2d(self, Time, ax, color="k", Xuvec=[1,0,0], Yuvec=[0,0,1], Xoff=0, Yoff=0, colortension=False, cmap='rainbow', plotnodes=[], plotnodesline=[], label="", alpha=1.0,linewidth=1):
'''Draw the line on 2D plot (ax must be 2D)
Parameters
Expand All @@ -434,6 +434,8 @@ def drawLine2d(self, Time, ax, color="k", Xuvec=[1,0,0], Yuvec=[0,0,1], Xoff=0,
toggle to plot the lines in a colormap based on node tensions. The default is False
cmap : string, optional
colormap string type to plot tensions when colortension=True. The default is 'rainbow'
linewidth: float, optional
sets the mooring lines linewidth in matplotlib. default is 1
Returns
-------
Expand Down Expand Up @@ -475,7 +477,7 @@ def drawLine2d(self, Time, ax, color="k", Xuvec=[1,0,0], Yuvec=[0,0,1], Xoff=0,
rgba = cmap_obj(color_ratio) # return the rbga values of the colormap of where the node tension is
linebit.append(ax.plot(Xs2d[i:i+2], Ys2d[i:i+2], color=rgba))
else:
linebit.append(ax.plot(Xs2d, Ys2d, lw=1, color=color, label=label, alpha=alpha)) # previously had lw=1 (linewidth)
linebit.append(ax.plot(Xs2d, Ys2d, lw=linewidth, color=color, label=label, alpha=alpha)) # previously had lw=1 (linewidth)

if len(plotnodes) > 0:
for i,node in enumerate(plotnodes):
Expand Down
10 changes: 6 additions & 4 deletions moorpy/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -3476,6 +3476,8 @@ def plot2d(self, Xuvec=[1,0,0], Yuvec=[0,0,1], ax=None, color=None, **kwargs):
plotnodesline = kwargs.get('plotnodesline' , [] ) # the list of line numbers that match up with the desired node to be plotted
label = kwargs.get('label' , "" ) # the label/marker name of a line in the System
draw_fairlead = kwargs.get('draw_fairlead' , False ) # toggle to draw large points for the fairleads
line_width = kwargs.get('linewidth' , 1 ) # toggle to set the mooring line width in "drawLine2d




Expand Down Expand Up @@ -3532,13 +3534,13 @@ def plot2d(self, Xuvec=[1,0,0], Yuvec=[0,0,1], ax=None, color=None, **kwargs):
j = j + 1
if color==None and 'material' in line.type:
if 'chain' in line.type['material']:
line.drawLine2d(time, ax, color=[.1, 0, 0], Xuvec=Xuvec, Yuvec=Yuvec, colortension=colortension, cmap=cmap_tension, plotnodes=plotnodes, plotnodesline=plotnodesline, label=label, alpha=alpha)
line.drawLine2d(time, ax, color=[.1, 0, 0], Xuvec=Xuvec, Yuvec=Yuvec, colortension=colortension, cmap=cmap_tension, plotnodes=plotnodes, plotnodesline=plotnodesline, label=label, alpha=alpha, linewidth=line_width)
elif 'rope' in line.type['material'] or 'polyester' in line.type['material']:
line.drawLine2d(time, ax, color=[.3,.5,.5], Xuvec=Xuvec, Yuvec=Yuvec, colortension=colortension, cmap=cmap_tension, plotnodes=plotnodes, plotnodesline=plotnodesline, label=label, alpha=alpha)
line.drawLine2d(time, ax, color=[.3,.5,.5], Xuvec=Xuvec, Yuvec=Yuvec, colortension=colortension, cmap=cmap_tension, plotnodes=plotnodes, plotnodesline=plotnodesline, label=label, alpha=alpha, linewidth=line_width)
else:
line.drawLine2d(time, ax, color=[0.3,0.3,0.3], Xuvec=Xuvec, Yuvec=Yuvec, colortension=colortension, cmap=cmap_tension, plotnodes=plotnodes, plotnodesline=plotnodesline, label=label, alpha=alpha)
line.drawLine2d(time, ax, color=[0.3,0.3,0.3], Xuvec=Xuvec, Yuvec=Yuvec, colortension=colortension, cmap=cmap_tension, plotnodes=plotnodes, plotnodesline=plotnodesline, label=label, alpha=alpha, linewidth=line_width)
else:
line.drawLine2d(time, ax, color=color, Xuvec=Xuvec, Yuvec=Yuvec, colortension=colortension, cmap=cmap_tension, plotnodes=plotnodes, plotnodesline=plotnodesline, label=label, alpha=alpha)
line.drawLine2d(time, ax, color=color, Xuvec=Xuvec, Yuvec=Yuvec, colortension=colortension, cmap=cmap_tension, plotnodes=plotnodes, plotnodesline=plotnodesline, label=label, alpha=alpha, linewidth=line_width)

# Add Line labels
if linelabels == True:
Expand Down

0 comments on commit 059fad9

Please sign in to comment.