Skip to content

Commit be5dfef

Browse files
committed
Modified the way data is accessed from pivoted_plot_data to avoid problems with NaN in some lines
1 parent a519f6f commit be5dfef

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

dabest/plotter.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -344,36 +344,25 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
344344
# Plot the raw data as a slopegraph.
345345
# Pivot the long (melted) data.
346346
if color_col is None:
347-
pivot_values = yvar
347+
pivot_values = [yvar]
348348
else:
349349
pivot_values = [yvar, color_col]
350350
pivoted_plot_data = pd.pivot(data=plot_data, index=dabest_obj.id_col,
351351
columns=xvar, values=pivot_values)
352352

353353
for ii, current_tuple in enumerate(idx):
354-
if len(idx) > 1:
355-
# Select only the data for the current tuple.
356-
if color_col is None:
357-
current_pair = pivoted_plot_data.reindex(columns=current_tuple)
358-
else:
359-
current_pair = pivoted_plot_data[yvar].reindex(columns=current_tuple)
360-
else:
361-
if color_col is None:
362-
current_pair = pivoted_plot_data
363-
else:
364-
current_pair = pivoted_plot_data[yvar]
354+
current_pair = pivoted_plot_data.loc[:, pd.MultiIndex.from_product([pivot_values, current_tuple])].dropna()
365355

366356
# Iterate through the data for the current tuple.
367357
for ID, observation in current_pair.iterrows():
368358
x_start = (ii * 2)
369359
x_points = [x_start, x_start+1]
370-
y_points = observation.tolist()
360+
y_points = observation[yvar].tolist()
371361

372362
if color_col is None:
373363
slopegraph_kwargs['color'] = ytick_color
374364
else:
375-
color_key = pivoted_plot_data[color_col,
376-
current_tuple[0]].loc[ID]
365+
color_key = observation[color_col][0]
377366
slopegraph_kwargs['color'] = plot_palette_raw[color_key]
378367
slopegraph_kwargs['label'] = color_key
379368

0 commit comments

Comments
 (0)