[Python] Why every time I make changes in the plot the Editable Line gets reset

Discussão em 'Python' iniciado por Stack, Junho 26, 2025.

  1. Stack

    Stack Membro Participativo

    Why every time I make changes in the plot the Editable Line gets reset, I want it to stay persistent unless i remove it

    def _add_editable_line(self, track_idx, x_val=None):
    """Add an editable line to the specified track"""
    if track_idx >= len(self.tracks):
    return

    ax = self.figure.axes[track_idx]
    track = self.tracks[track_idx]

    if x_val is None:
    xlim = ax.get_xlim()
    x_val = (xlim[0] + xlim[1]) / 2

    y_min, y_max = ax.get_ylim()
    y_points = np.linspace(y_min, y_max, 100)
    x_points = np.full_like(y_points, fill_value=x_val)

    line, = ax.plot(x_points, y_points,
    color='purple',
    linestyle='-',
    linewidth=2,
    marker='o',
    markersize=8,
    markerfacecolor='red',
    picker=True,
    pickradius=10)

    markers = []
    for x, y in zip(x_points, y_points):
    marker, = ax.plot([x], [y], 'o',
    color='red',
    markersize=10,
    picker=True,
    pickradius=15)
    markers.append(marker)

    self.editable_lines[track_idx] = {
    'line': line,
    'markers': markers,
    'ax': ax,
    'x': x_val
    }

    if hasattr(track, 'straight_line_value'):
    track.straight_line_value.setText(f"{x_val:.2f}")


    [![

    the purple line with red dots, i want it to maintain its state, while making changes in the plot. ]1]1

    Continue reading...

Compartilhe esta Página