Reputation: 709
I have a color coded plot. Here is a part of the code:
fig = plt.figure(figsize=(10,10))
color_scheme = plt.get_cmap('cool')
gs = gridspec.GridSpec(1, 1)
ax1 = plt.subplot(gs[0])
gs.update(left=0.15,bottom=0.15,right=0.80,top=0.95)
cax = fig.add_axes([0.80, 0.15, 0.03, 0.80])
im = ax1.scatter(x, y, c=z, edgecolors='black', marker='.', s=40, lw=1, cmap=color_scheme, vmin=0, vmax=10)
cb = fig.colorbar(im, cax=cax)
for t in cb.ax.get_yticklabels(): t.set_fontsize(12)
The problem is that I want to connect the dots with a line, and it doesn't work to use marker='-' and it also doesn't work if I use ax1.plt. How can I do this?
What I actually need is to fit a line to some points and color it the same color as the points (the points I fit to will all have same color)
Upvotes: 1
Views: 1549
Reputation: 1666
Plot the same x and y-data separately with a standard ax.plot
behind your scatter plot.
ax1.plot(x, y, '-')
im = ax1.scatter(x, y, c=z, edgecolors='black', marker='.', s=40, lw=1, cmap=color_scheme, vmin=0, vmax=10)
This should give you your cmapped scatter plot with the lines behind the scatter-points.
Upvotes: 1
Reputation: 27575
Instead of using
ax1.scatter(x, y, ...)
use
ax1.plot(x, y, 'o-', ...) # three dots meaning you can configure markers, linestyle, etc.
This works bacause of 'o-'
argument, which is a line plot with markers at every data point.
Upvotes: 2