Skip to content

Commit fae42cc

Browse files
committed
minor refactoring
1 parent 4b07e1c commit fae42cc

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

scikit_posthocs/_plotting.py

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -518,40 +518,36 @@ def critical_difference_diagram(
518518
ranks.iloc[len(ranks) // 2 :],
519519
)
520520

521-
# Sets of points under the same crossbar
521+
# Arrays of ranks for each crossbar (each crossbar is a maximal clique)
522522
crossbar_ranks = (
523523
ranks.reindex(bar).sort_values().values
524524
for bar in _find_maximal_cliques(adj_matrix)
525525
if len(bar) > 1
526526
)
527-
# Try to fit wider crossbars first
528-
crossbar_ranks = list(sorted(crossbar_ranks, key=lambda x: x[0] - x[-1]))
529-
530-
# If any crossbar is found, plot them
531-
if crossbar_ranks:
532-
# Create stacking of crossbars: for each level, try to fit the crossbar,
533-
# so that it does not intersect with any other in the level. If it does not
534-
# fit in any level, create a new level for it.
535-
crossbar_levels: list[list[np.ndarray]] = []
536-
for bar_i in crossbar_ranks:
537-
for bars_in_level in crossbar_levels:
538-
if all(
539-
(bar_i[-1] < bar_j[0]) or (bar_i[0] > bar_j[-1])
540-
for bar_j in bars_in_level
541-
):
542-
bars_in_level.append(bar_i)
543-
break
544-
else:
545-
crossbar_levels.append([bar_i]) # Create a new level
546-
547-
# Plot crossbars
548-
# We could plot a single line segment between min and max. However,
549-
# adding a separate segment between each pair enables showing a
550-
# marker over each elbow, e.g. crossbar_props={'marker': 'o'}.
551-
crossbars = [
552-
[ax.plot(bar, [-i] * len(bar), **crossbar_props) for bar in level]
553-
for i, level in enumerate(crossbar_levels)
554-
]
527+
528+
# Create stacking of crossbars: for each level, try to fit the widest crossbar,
529+
# so that it does not intersect with any other in the level. If it does not
530+
# fit in any level, create a new level for it.
531+
crossbar_levels: list[list[np.ndarray]] = []
532+
for bar_i in sorted(crossbar_ranks, key=lambda x: x[0] - x[-1]):
533+
for bars_in_level in crossbar_levels:
534+
if all(
535+
(bar_i[-1] < bar_j[0]) or (bar_i[0] > bar_j[-1])
536+
for bar_j in bars_in_level
537+
):
538+
bars_in_level.append(bar_i)
539+
break
540+
else:
541+
crossbar_levels.append([bar_i]) # Create a new level
542+
543+
# Plot crossbars.
544+
# We could plot a single line segment for the whole crossbar. However,
545+
# we add a separate segment between each elbow, enabling the display of a
546+
# marker over each elbow, e.g. crossbar_props={'marker': 'o'}.
547+
crossbars = [
548+
[ax.plot(bar, [-i] * len(bar), **crossbar_props) for bar in level]
549+
for i, level in enumerate(crossbar_levels)
550+
]
555551

556552
elbow_start_y = -len(crossbars)
557553

0 commit comments

Comments
 (0)