Last active
November 21, 2023 15:33
-
-
Save barrysmyth/c322631815a5206f69d7237b4a410927 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plot_heatline(ax, x, y, c, w): | |
"""Plot a colour-coded segmented line graph with a border. | |
Args: | |
ax - the current axis. | |
x - x-axis values. | |
y - y-axis values. | |
c - the colours for the segments in the line graph defined by x, y. | |
w - the line widths for the segments in the line graph defined by x, y. | |
""" | |
# Reformat the x, y data to define the segments needed by LineCollection. | |
points = np.array([x, y]).T.reshape(-1, 1, 2) # Create Nx1x2 array | |
segments = np.concatenate( | |
[points[:-1], points[1:]] | |
, axis=1 | |
) # Pairs of (x,y) points for each segment. | |
# Build the heat line; each segment with teh segment colors and widths. | |
heat_line = LineCollection(segments, colors=c, linewidths=w) | |
ax.add_collection(heat_line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment