7

I plot a figure as below:

plt.plot(lon,lat,'ro-')
plt.show()

enter image description here

but the lines aren't closed. How can I make them closed as polygons? thank you

2 Answers 2

17

Use matplotlib.pyplot.fill(lon,lat,fill=False) instead of plot().

See http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.fill for details. The color string refers to the interior, so to use red for the polygon, use

plt.fill(lon, lat, edgecolor='r', fill=False)

and continue to use plot() to place circles on the vertices if desired.

Sign up to request clarification or add additional context in comments.

Comments

1

A helper method I use:

def plotPolygonOutline(points: List[Tuple[float, float]], color='r', lineWidth=1):
    x, y = map(list, zip(*points))
    x.append(x[0])
    y.append(y[0])
    plt.plot(x, y, marker='o', color=color, linewidth=lineWidth)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.