Different marker colors for start and end points in pyplot
<p>I am trying to plot lines on a plot between two point tuples. I have following arrays:</p>

<pre><code>start_points = [(54.6, 35.2), (55.5, 32.7), (66.5, 23.7), (75.5, 47.8), (89.3, 19.7)]
end_points = [(38.9, 44.3), (46.7, 52.2), (72.0, 1.4), (62.3, 18.9), (80.8, 26.2)]
</code></pre>

<p>So what I am trying to do is drawing lines between points at same index like a line from (54.6, 35.2) to (38.9, 44.3), another line from (55.5, 32.7) to (46.7, 52.2) and so on.</p>

<p>I achieved this by plotting <code>zip(start_points[:5], end_points[:5])</code>, but I want different marker styles for start and end points of lines. I want start_points to be green circle, and end_points to be blue x for example. Is this possible?</p>

<p>The trick is to first plot the line (<code>plt.plot</code>) and then plot the markers using a scatter plot (<code>plt.scatter</code>).</p>

<pre><code>import numpy as np
from matplotlib import pyplot as plt

start_points = [(54.6, 35.2), (55.5, 32.7), (66.5, 23.7), (75.5, 47.8), (89.3, 19.7)]
end_points = [(38.9, 44.3), (46.7, 52.2), (72.0, 1.4), (62.3, 18.9), (80.8, 26.2)]

for line in zip(start_points, end_points):
    line = np.array(line)
    plt.plot(line[:, 0], line[:, 1], color='black', zorder=1)
    plt.scatter(line[0, 0], line[0, 1], marker='o', color='green', zorder=2)
    plt.scatter(line[1, 0], line[1, 1], marker='x', color='red', zorder=2)
</code></pre>

python matplotlib