Skip to content

Commit

Permalink
allow data_label_filter arg
Browse files Browse the repository at this point in the history
  • Loading branch information
zhang-ivy committed Jan 24, 2023
1 parent 198182f commit 2764be6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cinnabar/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ def _master_plot(
figsize: float = 3.25,
dpi: Union[float, str] = "figure",
data_labels: list = [],
data_label_filter: Optional[float] = None,
axis_padding: float = 0.5,
xy_lim: list = [],
font_sizes: dict = {"title": 12, "labels": 9, "other": 12},
marker_size : float = 10,
marker_size: float = 10,
):
"""Handles the aesthetics of the plots in one place.
Expand Down Expand Up @@ -82,6 +83,8 @@ def _master_plot(
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html)
data_labels : list of str, default []
list of labels for each data point
data_label_filter : float, default None
only show labels for data points where the abs(x - y) > data_label_filter
axis_padding : float, default = 0.5
padding to add to maximum axis value and subtract from the minimum axis value
xy_lim : list, default []
Expand Down Expand Up @@ -162,8 +165,13 @@ def _master_plot(
plt.scatter(x, y, color=color, s=marker_size, marker="o", zorder=2)

# Label points
# If data_label_filter is specified, only label data points that are outliers
# (i.e. where the difference in x and y is larger than data_label_filter)
texts = []
for i, label in enumerate(data_labels):
if data_label_filter is not None:
if abs(x[i] - y[i]) <= data_label_filter:
continue
texts.append(plt.text(x[i] + 0.03, y[i] + 0.03, label, fontsize=font_sizes["labels"]))
adjust_text(texts)

Expand Down

0 comments on commit 2764be6

Please sign in to comment.