Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel coordinate plot option added #1088

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add options
  • Loading branch information
lee1043 committed Apr 30, 2024
commit 58ab307cee8c7e90b75be7cac5863ac44b0f4d18
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ def parallel_coordinate_plot(
arrow_between_lines=False,
arrow_between_lines_colors=("red", "green"),
arrow_alpha=1,
arrow_width=0.05,
arrow_linewidth=0,
arrow_head_width=0.15,
arrow_head_length=0.15,
vertical_center=None,
vertical_center_line=False,
vertical_center_line_label=None,
ymax=None,
ymin=None,
debug=False,
):
"""
Parameters
Expand Down Expand Up @@ -99,11 +104,15 @@ def parallel_coordinate_plot(
- `arrow_between_lines`: bool, default=False, place arrows between two lines for models in comparing_models
- `arrow_between_lines_colors`: tuple or list containing two strings of colors for arrow between the two lines. Default=('red', 'green')
- `arrow_alpha`: float, default=1, transparency of arrow (faction between 0 to 1)
- `arrow_width`: float, default is 0.05, width of arrow
- `arrow_linewidth`: float, default is 0, width of arrow edge line
- `arrow_head_width`: float, default is 0.15, widht of arrow head
- `arrow_head_length`: float, default is 0.15, length of arrow head
- `vertical_center`: string ("median", "mean")/float/integer, default=None, adjust range of vertical axis to set center of vertical axis as median, mean, or given number
- `vertical_center_line`: bool, default=False, show median as line
- `vertical_center_line_label`: str, default=None, label in legend for the horizontal vertical center line. If not given, it will be automatically assigned. It can be turned off by "off"
- `ymax`: int or float, default=None, specify value of vertical axis top
- `ymin`: int or float, default=None, specify value of vertical axis bottom
- `ymax`: int or float or string ('percentile'), default=None, specify value of vertical axis top. If percentile, 95th percentile or extended for top
- `ymin`: int or float or string ('percentile'), default=None, specify value of vertical axis bottom. If percentile, 5th percentile or extended for bottom

Return
------
Expand All @@ -117,6 +126,7 @@ def parallel_coordinate_plot(
2023-03 median centered option added
2023-04 vertical center option diversified (median, mean, or given number)
2024-03 parameter added for violin plot label
2024-04 parameters added for arrow and option added for ymax/ymin setting
"""
params = {
"legend.fontsize": "large",
Expand All @@ -142,6 +152,10 @@ def parallel_coordinate_plot(
ymax=ymax,
ymin=ymin,
)

if debug:
print("ymins:", ymins)
print("ymaxs:", ymaxs)

# Prepare plot
if N > 20:
Expand Down Expand Up @@ -317,8 +331,8 @@ def parallel_coordinate_plot(
alpha=0.5,
)

# Add vertical arrows
if arrow_between_lines:
# Add vertical arrows
for xi, yi1, yi2 in zip(x, y1, y2):
if yi2 > yi1:
arrow_color = arrow_between_lines_colors[0]
Expand All @@ -335,8 +349,11 @@ def parallel_coordinate_plot(
color=arrow_color,
length_includes_head=True,
alpha=arrow_alpha,
width=0.05,
head_width=0.15,
width=arrow_width,
linewidth=arrow_linewidth,
head_width=arrow_head_width,
head_length=arrow_head_length,
zorder=999,
)

ax.set_xlim(-0.5, N - 0.5)
Expand Down Expand Up @@ -427,7 +444,7 @@ def _data_transform(
else:
try:
if isinstance(ymax, str) and ymax == "percentile":
ymaxs = np.percentile(ys, 95, axis=0)
ymaxs = np.nanpercentile(ys, 95, axis=0)
else:
ymaxs = np.repeat(ymax, N)
except ValueError:
Expand All @@ -438,7 +455,7 @@ def _data_transform(
else:
try:
if isinstance(ymin, str) and ymin == "percentile":
ymins = np.percentile(ys, 5, axis=0)
ymins = np.nanpercentile(ys, 5, axis=0)
else:
ymins = np.repeat(ymin, N)
except ValueError:
Expand Down
Loading