I was intrigued by a command line that I don’t understand, given in the answer of the (already old) post HERE.
So, I tried to investigate and made the following program:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
from scipy.spatial import Delaunay, delaunay_plot_2d
np.random.seed(12345)
points = np.random.rand(8, 2)
tri = Delaunay(points)
fig, ax = plt.subplots(figsize=(8, 4))
D = delaunay_plot_2d(tri, ax=ax)
ax.set_aspect('equal', 'box')
list = [l for l in D.axes[0].get_children() if type(l) is Line2D]
list
which gave me 3
items in the list
:
[<matplotlib.lines.Line2D at 0x246dd230550>,
<matplotlib.lines.Line2D at 0x246dd230850>,
<matplotlib.lines.Line2D at 0x246dd230af0>]
I then could use the 1st
item to change the color of the points:
patch_point = [l for l in D.axes[0].get_children() if type(l) is Line2D][0]
patch_point.set_color('blue')
and the 2nd
item to change the color of the lines:
patch_line = [l for l in D.axes[0].get_children() if type(l) is Line2D][1]
patch_line.set_color('green')
but what is the meaning of the 3rd
item? For example, the following lines doesn’t change anything…
patch_what = [l for l in D.axes[0].get_children() if type(l) is Line2D][2]
patch_what.set_color('red')
Could someone help me understanding what this strange command [l for l in D.axes[0].get_children() if type(l) is Line2D]
does?