Ich zeichne geografische Höhenkurven. Dies mache ich in matplotlib mit der LineCollection-Funktion. Das heisst, aus meinen Daten zeichnen ich Kurve um Kurve meines Bereiches.
Code: Alles auswählen
shapes = sf.shapes()
records = sf.records()
for record, shape in zip(records, shapes):
y, x = zip(*shape.points)
lats, lons = swiss2wgs(np.array(x), np.array(y))
data = np.array(m(lons, lats)).T
if len(shape.parts) == 1:
segs = [data, ]
else:
segs = []
for i in range(1, len(shape.parts)):
index = shape.parts[i - 1]
index2 = shape.parts[i]
segs.append(data[index:index2])
segs.append(data[index2:])
lines = LineCollection(segs, antialiaseds=(1,))
lines.set_edgecolors(color)
lines.set_linewidth(linewidth)
ax.add_collection(lines)
plt.show()
Ich kann zwar die Farbe in Abhängigkeit der Höhe wechseln:
Code: Alles auswählen
yMin = 0; yMax = 4000
ticks = np.linspace(yMin, yMax, 20)
cm = LinearSegmentedColormap.from_list("cm", ["#81fcff", "#19ff19", "#e2f000", "#ffaa31", "#ff8e51", "#ff6969",
"#8c0000", "#3c0000"])
cNorm = matplotlib.colors.Normalize(0, 1)
scalarMap = matplotlib.cm.ScalarMappable(norm=cNorm, cmap=cm)
...
...
color = scalarMap.to_rgba((record[2] - yMin) / (yMax - yMin) )
lines.set_edgecolors(color)
Ist es möglich die einzelnen Höhenlinien so farbig darzustellen, damit diese einem System von Farben entspricht?
Danke und Gruss, Jakob