Matplotlib: Use Fill_between To Make Coloured Triangles
I've plotted random triangles in space with code below but I want to fill the triangles with colour. I'm aware of the fill_between() function in matplotlib, however I am not sure h
Solution 1:
You could use plt.fill()
as follows:
import matplotlib.pyplot as plt
trianglex = [ 1, 10, 7, 1 ]
triangley = [ 2, 8, 4, 2 ]
triangle2x = [ 13, 25, 21, 13]
triangle2y = [ 5, 7 , 14, 5 ]
plt.figure('Triangles')
for i in range(3):
plt.plot(trianglex, triangley, 'o-')
plt.fill(trianglex, triangley)
for i in range(3):
plt.plot( triangle2x, triangle2y, 'o-')
plt.fill(triangle2x, triangle2y)
plt.show()
Output
Post a Comment for "Matplotlib: Use Fill_between To Make Coloured Triangles"