Implement a plot method for PlotData Objects
Closed this issue · 1 comments
-
I'm submitting a ...
- feature request
-
What is the current behavior?
One need to call the plot_canvas
method defined in the core module of plot_data.
- What is the expected behavior?
plot should be callable from objects directly
- What is the motivation / use case for changing the behavior?
The current implementation is problematic because one need to import plot_data in order to plot locally. By implementing a method for plot_data objects, we could only call object_.plot()
, as we know for a fact that we are handling plot data objects and get rid of this import, namely in dessia_common for example. Consider the following dessia common implementation. This change would enable us to get rid of that lousy plot_data import
def plot(self, selector: Optional[DISPLAY_TYPES] = None, **kwargs):
"""
Generic plot getting object plot_data views in order to plot locally.
First, get all settings defined by a 'plot_data_view' decorator.
If a selector is set, it only plots the desired one.
If selector is None, plots every plot candidate
"""
plot_data_settings = self._display_settings_from_type("plot_data", **kwargs)
if selector is None:
display_objects = [self._display_from_selector(selector=d.selector, serialize_data=False)
for d in plot_data_settings]
msg = f"Class '{self.full_classname}' does not define any display of type 'plot_data'."
else:
display_objects = [self._display_from_selector(selector=d.selector, serialize_data=False)
for d in plot_data_settings if d.selector == selector]
msg = (f"No selector '{selector}' found in class '{self.full_classname}'"
f"definition for displays of type 'plot_data'.")
if not display_objects:
raise ValueError(msg)
import plot_data
for display_object in display_objects:
plot_data_object = display_object.data
try:
# Ideally
plot_data_object.plot()
except AttributeError:
# Supporting plot_data < 0.22.0
# Removing this and using statement above would remove plot_data requirement
plot_data.plot_canvas(plot_data_object=plot_data_object, canvas_id='canvas',
width=1400, height=900, debug_mode=False)
-
Possible fixes
-
Please tell us about your environment:
- branch:
- commit:
- python version:
Actually realized that this is already done in current master and dev version.