Skip to content

Commit

Permalink
Rename plot-options to figure-options
Browse files Browse the repository at this point in the history
  • Loading branch information
conradhaupt committed Sep 26, 2022
1 parent 9f4e1ee commit 956696a
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 112 deletions.
2 changes: 1 addition & 1 deletion qiskit_experiments/curve_analysis/curve_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def __init__(
"symbol": series_def.plot_symbol,
"canvas": series_def.canvas,
}
self.plotter.set_plot_options(series_params=series_params)
self.plotter.set_figure_options(series_params=series_params)

self._models = models or []
self._name = name or self.__class__.__name__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _default_options(cls):
input_key="counts",
data_actions=[dp.Probability("1"), dp.BasisExpectationValue()],
)
default_options.plotter.set_plot_options(
default_options.plotter.set_figure_options(
xlabel="Flat top width",
ylabel="Pauli expectation values",
xval_unit="s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _default_options(cls):
considered as good. Defaults to :math:`\pi/2`.
"""
default_options = super()._default_options()
default_options.plotter.set_plot_options(
default_options.plotter.set_figure_options(
xlabel="Number of gates (n)",
ylabel="Population",
ylim=(0, 1.0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(
@classmethod
def _default_options(cls) -> Options:
options = super()._default_options()
options.plotter.set_plot_options(
options.plotter.set_figure_options(
xlabel="Frequency",
ylabel="Signal (arb. units)",
xval_unit="Hz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(
@classmethod
def _default_options(cls) -> Options:
options = super()._default_options()
options.plotter.set_plot_options(
options.plotter.set_figure_options(
xlabel="Frequency",
ylabel="Signal (arb. units)",
xval_unit="Hz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _default_options(cls):
text_box_rel_pos=(0.28, -0.10),
),
)
default_options.plotter.set_plot_options(
default_options.plotter.set_figure_options(
xlabel="Flat top width",
ylabel=[
r"$\langle$X(t)$\rangle$",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _default_options(cls):
descriptions of analysis options.
"""
default_options = super()._default_options()
default_options.plotter.set_plot_options(
default_options.plotter.set_figure_options(
xlabel="Beta",
ylabel="Signal (arb. units)",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _default_options(cls):
descriptions of analysis options.
"""
default_options = super()._default_options()
default_options.plotter.set_plot_options(
default_options.plotter.set_figure_options(
xlabel="Delay",
ylabel="Signal (arb. units)",
xval_unit="s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class T1Analysis(curve.DecayAnalysis):
def _default_options(cls) -> Options:
"""Default analysis options."""
options = super()._default_options()
options.plotter.set_plot_options(
options.plotter.set_figure_options(
xlabel="Delay",
ylabel="P(1)",
xval_unit="s",
Expand Down Expand Up @@ -85,7 +85,7 @@ class T1KerneledAnalysis(curve.DecayAnalysis):
def _default_options(cls) -> Options:
"""Default analysis options."""
options = super()._default_options()
options.plotter.set_plot_options(
options.plotter.set_figure_options(
xlabel="Delay",
ylabel="Normalized Projection on the Main Axis",
xval_unit="s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class T2HahnAnalysis(curve.DecayAnalysis):
def _default_options(cls) -> Options:
"""Default analysis options."""
options = super()._default_options()
options.plotter.set_plot_options(
options.plotter.set_figure_options(
xlabel="Delay",
ylabel="P(0)",
xval_unit="s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class T2RamseyAnalysis(curve.DampedOscillationAnalysis):
def _default_options(cls) -> Options:
"""Default analysis options."""
options = super()._default_options()
options.plotter.set_plot_options(
options.plotter.set_figure_options(
xlabel="Delay",
ylabel="P(1)",
xval_unit="s",
Expand Down
2 changes: 1 addition & 1 deletion qiskit_experiments/library/characterization/rabi.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(
result_parameters=[ParameterRepr("freq", self.__outcome__)],
normalization=True,
)
self.analysis.plotter.set_plot_options(
self.analysis.plotter.set_figure_options(
xlabel="Amplitude",
ylabel="Signal (arb. units)",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _default_options(cls):
2Q RB is corrected to exclude the depolarization of underlying 1Q channels.
"""
default_options = super()._default_options()
default_options.plotter.set_plot_options(
default_options.plotter.set_figure_options(
xlabel="Clifford Length",
ylabel="P(0)",
)
Expand Down
56 changes: 28 additions & 28 deletions qiskit_experiments/visualization/drawers/base_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ def __init__(self):
# A set of changed options for serialization.
self._set_options = set()

# Plot options which are typically updated by a plotter instance. Plot-options include the axis
# labels, figure title, and a custom style instance.
self._plot_options = self._default_plot_options()
# A set of changed plot-options for serialization.
self._set_plot_options = set()
# Figure options which are typically updated by a plotter instance. Figure-options include the
# axis labels, figure title, and a custom style instance.
self._figure_options = self._default_figure_options()
# A set of changed figure-options for serialization.
self._set_figure_options = set()

# The initialized axis/axes, set by `initialize_canvas`.
self._axis = None
Expand All @@ -97,14 +97,14 @@ def options(self) -> Options:
return self._options

@property
def plot_options(self) -> Options:
"""Return the plot options.
def figure_options(self) -> Options:
"""Return the figure options.
These are typically updated by a plotter instance, and thus may change. It is recommended to set
plot options in a parent :class:`BasePlotter` instance that contains the :class:`BaseDrawer`
figure options in a parent :class:`BasePlotter` instance that contains the :class:`BaseDrawer`
instance.
"""
return self._plot_options
return self._figure_options

@classmethod
def _default_options(cls) -> Options:
Expand All @@ -130,10 +130,10 @@ def _default_style(cls) -> PlotStyle:
return PlotStyle.default_style()

@classmethod
def _default_plot_options(cls) -> Options:
"""Return default plot options.
def _default_figure_options(cls) -> Options:
"""Return default figure options.
Plot Options:
Figure Options:
xlabel (Union[str, List[str]]): X-axis label string of the output figure.
If there are multiple columns in the canvas, this could be a list of labels.
ylabel (Union[str, List[str]]): Y-axis label string of the output figure.
Expand All @@ -153,7 +153,7 @@ def _default_plot_options(cls) -> Options:
displayed in the scientific notation.
yval_unit (str): Unit of y values. See ``xval_unit`` for details.
figure_title (str): Title of the figure. Defaults to None, i.e. nothing is shown.
series_params (Dict[str, Dict[str, Any]]): A dictionary of plot parameters for each series.
series_params (Dict[str, Dict[str, Any]]): A dictionary of parameters for each series.
This is keyed on the name for each series. Sub-dictionary is expected to have following
three configurations, "canvas", "color", and "symbol"; "canvas" is the integer index of
axis (when multi-canvas plot is set), "color" is the color of the series, and "symbol" is
Expand Down Expand Up @@ -188,33 +188,33 @@ def set_options(self, **fields):
self._options.update_options(**fields)
self._set_options = self._set_options.union(fields)

def set_plot_options(self, **fields):
"""Set the plot options.
def set_figure_options(self, **fields):
"""Set the figure options.
Args:
fields: The fields to update the plot options
fields: The fields to update the figure options
"""
for field in fields:
if not hasattr(self._plot_options, field):
if not hasattr(self._figure_options, field):
raise AttributeError(
f"Plot options field {field} is not valid for {type(self).__name__}"
f"Figure options field {field} is not valid for {type(self).__name__}"
)
self._plot_options.update_options(**fields)
self._set_plot_options = self._set_plot_options.union(fields)
self._figure_options.update_options(**fields)
self._set_figure_options = self._set_figure_options.union(fields)

@property
def style(self) -> PlotStyle:
"""The combined plot style for this drawer.
The returned style instance is a combination of :attr:`options.default_style` and
:attr:`plot_options.custom_style`. Style parameters set in ``custom_style`` override those set in
:attr:`figure_options.custom_style`. Style parameters set in ``custom_style`` override those set in
``default_style``. If ``custom_style`` is not an instance of :class:`PlotStyle`, the returned
style is equivalent to ``default_style``.
Returns:
PlotStyle: The plot style for this drawer.
"""
if isinstance(self.plot_options.custom_style, PlotStyle):
return PlotStyle.merge(self.options.default_style, self.plot_options.custom_style)
if isinstance(self.figure_options.custom_style, PlotStyle):
return PlotStyle.merge(self.options.default_style, self.figure_options.custom_style)
return self.options.default_style

@abstractmethod
Expand Down Expand Up @@ -341,14 +341,14 @@ def figure(self):
def config(self) -> Dict:
"""Return the config dictionary for this drawer."""
options = dict((key, getattr(self._options, key)) for key in self._set_options)
plot_options = dict(
(key, getattr(self._plot_options, key)) for key in self._set_plot_options
figure_options = dict(
(key, getattr(self._figure_options, key)) for key in self._set_figure_options
)

return {
"cls": type(self),
"options": options,
"plot_options": plot_options,
"figure_options": figure_options,
}

def __json_encode__(self):
Expand All @@ -359,6 +359,6 @@ def __json_decode__(cls, value):
instance = cls()
if "options" in value:
instance.set_options(**value["options"])
if "plot_options" in value:
instance.set_plot_options(**value["plot_options"])
if "figure_options" in value:
instance.set_figure_options(**value["figure_options"])
return instance
32 changes: 16 additions & 16 deletions qiskit_experiments/visualization/drawers/mpl_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def initialize_canvas(self):
sub_ax.set_yticklabels([])
else:
# this axis locates at left, write y-label
if self.plot_options.ylabel:
label = self.plot_options.ylabel
if self.figure_options.ylabel:
label = self.figure_options.ylabel
if isinstance(label, list):
# Y label can be given as a list for each sub axis
label = label[i]
Expand All @@ -98,8 +98,8 @@ def initialize_canvas(self):
sub_ax.set_xticklabels([])
else:
# this axis locates at bottom, write x-label
if self.plot_options.xlabel:
label = self.plot_options.xlabel
if self.figure_options.xlabel:
label = self.figure_options.xlabel
if isinstance(label, list):
# X label can be given as a list for each sub axis
label = label[j]
Expand All @@ -112,8 +112,8 @@ def initialize_canvas(self):
# Remove original axis frames
axis.axis("off")
else:
axis.set_xlabel(self.plot_options.xlabel, fontsize=self.style.axis_label_size)
axis.set_ylabel(self.plot_options.ylabel, fontsize=self.style.axis_label_size)
axis.set_xlabel(self.figure_options.xlabel, fontsize=self.style.axis_label_size)
axis.set_ylabel(self.figure_options.ylabel, fontsize=self.style.axis_label_size)
axis.tick_params(labelsize=self.style.tick_label_size)
axis.grid()

Expand All @@ -136,11 +136,11 @@ def format_canvas(self):
for ax_type in ("x", "y"):
# Get axis formatter from drawing options
if ax_type == "x":
lim = self.plot_options.xlim
unit = self.plot_options.xval_unit
lim = self.figure_options.xlim
unit = self.figure_options.xval_unit
else:
lim = self.plot_options.ylim
unit = self.plot_options.yval_unit
lim = self.figure_options.ylim
unit = self.figure_options.yval_unit

# Compute data range from auto scale
if not lim:
Expand Down Expand Up @@ -213,9 +213,9 @@ def format_canvas(self):
ax1.sharey(ax2)
all_axes[0].set_ylim(lim)
# Add title
if self.plot_options.figure_title is not None:
if self.figure_options.figure_title is not None:
self._axis.set_title(
label=self.plot_options.figure_title,
label=self.figure_options.figure_title,
fontsize=self.style.axis_label_size,
)

Expand Down Expand Up @@ -308,7 +308,7 @@ def draw_scatter(
**options,
):

series_params = self.plot_options.series_params.get(name, {})
series_params = self.figure_options.series_params.get(name, {})
marker = series_params.get("symbol", self._get_default_marker(name))
color = series_params.get("color", self._get_default_color(name))
axis = series_params.get("canvas", None)
Expand Down Expand Up @@ -352,7 +352,7 @@ def draw_line(
legend_label: Optional[str] = None,
**options,
):
series_params = self.plot_options.series_params.get(name, {})
series_params = self.figure_options.series_params.get(name, {})
axis = series_params.get("canvas", None)
color = series_params.get("color", self._get_default_color(name))

Expand All @@ -375,7 +375,7 @@ def draw_filled_y_area(
legend_label: Optional[str] = None,
**options,
):
series_params = self.plot_options.series_params.get(name, {})
series_params = self.figure_options.series_params.get(name, {})
axis = series_params.get("canvas", None)
color = series_params.get("color", self._get_default_color(name))

Expand All @@ -397,7 +397,7 @@ def draw_filled_x_area(
legend_label: Optional[str] = None,
**options,
):
series_params = self.plot_options.series_params.get(name, {})
series_params = self.figure_options.series_params.get(name, {})
axis = series_params.get("canvas", None)
color = series_params.get("color", self._get_default_color(name))

Expand Down
Loading

0 comments on commit 956696a

Please sign in to comment.