rgerum / pylustrator

Visualisations of data are at the core of every publication of scientific research results. They have to be as clear as possible to facilitate the communication of research. As data can have different formats and shapes, the visualisations often have to be adapted to reflect the data as well as possible. We developed Pylustrator, an interface to directly edit python generated matplotlib graphs to finalize them for publication. Therefore, subplots can be resized and dragged around by the mouse, text and annotations can be added. The changes can be saved to the initial plot file as python code.
GNU General Public License v3.0
707 stars 37 forks source link

Exception when trying to edit text/labels #32

Closed cycomanic closed 3 years ago

cycomanic commented 3 years ago

Great project! Really what was missing for matplotlib

I'm trying to adjust some figures and I get an exception when trying to edit any text object (including axis labels). As a test-case I generate a plot using the script below:

import matplotlib.pyplot as plt
import pylustrator
import numpy as np
pylustrator.start()

plt.plot(np.arange(10), np.arange(10))
plt.show()

If I then edit the xlabel I get the following exception:

Traceback (most recent call last):
  File "/home/jschrod/.local/lib/python3.9/site-packages/pylustrator/QLinkableWidgets.py", line 120, in updateLink
    elements = self.setLinkedProperty(self.get())
  File "/home/jschrod/.local/lib/python3.9/site-packages/pylustrator/QLinkableWidgets.py", line 67, in set
    if isinstance(self.element, Text) and isinstance(self.element.figure.selection.targets[0].target, Axes):
IndexError: list index out of range
rgerum commented 3 years ago

hmm strange. What do you exactly do? Probably "click on the plot" and then "enter text in the xlabel box" and then when you click away from it the error occurs?

cycomanic commented 3 years ago

Ok I see what the issue was. I simply selected the subplot in the tree dialog on the left and entered the labels then. When I select the subplot in the graph and then edit the label it works. Not sure if this is a bug on intended behavior, I did expect selection in the tree view to also work.

rgerum commented 3 years ago

Well it is not expected behaviour to not work when you click it in the tree. Maybe it only works in the tree when you have for the first time selected an element graphics. I will try to find out whats happening. Thanks for the clarification, that will help me reproduce the bug.