Take the 2-minute tour ×

I have no idea how to plot the following. My data file contains the corner points of many triangulars in the following structure:

1 0
0 1
1 1

0.1 1
0.2 2
0.3 3

I want to draw them in one image and color the surface of each triangles differently. How do I do that?

Thanks for the help : )

share|improve this question
add comment

closed as unclear what you're asking by agf, Andy, Ben Bolker, PearsonArtPhoto, Chris Mar 3 at 0:49


2 Answers

up vote 1 down vote accepted

a quick look at artist demo

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
fig = plt.figure(figsize=(5,5))
ax = plt.axes([0,0,1,1])
triangle1 = mpatches.Polygon(np.array([[0,1],[1,0],[1,1]]), fc="blue")
triangle2 = mpatches.Polygon(np.array([[-0.1,-1],[-2,-2],[-2,-1]]), fc="red")
ax.set_xlim(-3, 3)
ax.set_ylim(-3, 3)


share|improve this answer
add comment

Using the data you posted:

import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
import itertools


with open('data') as f:
    for points in zip(*[itertools.ifilter(lambda line: line.strip(),f)]*3):
        points=([tuple(map(float,p.strip().split())) for p in points])

enter image description here

share|improve this answer
add comment
