Skip to content

Commit 558c494

Browse files
committed
fix plot multi color line to not skip the last color
1 parent 7158f11 commit 558c494

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/abg_python/plot_utils.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
latex_pagewidth=6.9738480697 ## in
1717
latex_columnwidth=3.32 ## in
1818

19-
from .pfh_colormaps import load_my_custom_color_tables
20-
try: load_my_custom_color_tables()
21-
except: pass ## don't want to re-register a colormap if plot_utils is imported multiple times
19+
#from .pfh_colormaps import load_my_custom_color_tables
20+
#try: load_my_custom_color_tables()
21+
#except: pass ## don't want to re-register a colormap if plot_utils is imported multiple times
22+
2223
try: import palettable
2324
except: pass #print("palettable colormaps are not installed")
2425

26+
plt.rcParams['figure.dpi'] = 120
27+
2528

2629
"""
2730
try:
@@ -385,7 +388,7 @@ def addSegmentedColorbar(ax,colors,vmin,vmax,label,logflag=0,fontsize=16,cmap_nu
385388
cb.ax.tick_params(labelsize=fontsize-2)
386389
return lambda x: cmap(norm(x))
387390

388-
def plotMulticolorLine(ax,xs,ys,zs,cmap,n_interp=50,**kwargs):
391+
def plotMulticolorLine(ax,xs,ys,zs,cmap='viridis',n_interp=50,**kwargs):
389392
"""
390393
takes x/y values and creates a line collection object
391394
of line segments between points in x/y colored by cmap(zs).
@@ -396,9 +399,15 @@ def plotMulticolorLine(ax,xs,ys,zs,cmap,n_interp=50,**kwargs):
396399
ys = linearInterpolate(ys,n_interp)
397400
zs = linearInterpolate(zs,n_interp)
398401

402+
n_interp = max(3,n_interp)
399403
points = np.array([xs, ys]).T.reshape(-1, 1, 2)
400404
segments = np.concatenate([points[:-1], points[1:]], axis=1)
401405

406+
## duplicate the final entry because otherwise it's ignored and you don't
407+
## make it to zs[-1] ever, no matter how many n_interp you have
408+
segments = np.append(segments,segments[-1:],axis=0)
409+
zs = np.append(zs,zs[-1])
410+
402411
lc = LineCollection(segments, cmap=cmap,norm=plt.Normalize(0, 1),**kwargs)
403412
lc.set_array(zs)
404413
lc.set_linewidth(3)

0 commit comments

Comments
 (0)