|
452 | 452 | " # Plot the raw data as a slopegraph.\n", |
453 | 453 | " # Pivot the long (melted) data.\n", |
454 | 454 | " if color_col is None:\n", |
455 | | - " pivot_values = yvar\n", |
| 455 | + " pivot_values = [yvar]\n", |
456 | 456 | " else:\n", |
457 | 457 | " pivot_values = [yvar, color_col]\n", |
458 | 458 | " pivoted_plot_data = pd.pivot(data=plot_data, index=dabest_obj.id_col,\n", |
459 | 459 | " columns=xvar, values=pivot_values)\n", |
460 | 460 | " x_start = 0\n", |
461 | 461 | " for ii, current_tuple in enumerate(temp_idx):\n", |
462 | | - " if len(temp_idx) > 1:\n", |
463 | | - " # Select only the data for the current tuple.\n", |
464 | | - " if color_col is None:\n", |
465 | | - " current_pair = pivoted_plot_data.reindex(columns=current_tuple)\n", |
466 | | - " else:\n", |
467 | | - " current_pair = pivoted_plot_data[yvar].reindex(columns=current_tuple)\n", |
468 | | - " else:\n", |
469 | | - " if color_col is None:\n", |
470 | | - " current_pair = pivoted_plot_data\n", |
471 | | - " else:\n", |
472 | | - " current_pair = pivoted_plot_data[yvar]\n", |
| 462 | + " current_pair = pivoted_plot_data.loc[:, pd.MultiIndex.from_product([pivot_values, current_tuple])].dropna()\n", |
473 | 463 | " grp_count = len(current_tuple)\n", |
474 | 464 | " # Iterate through the data for the current tuple.\n", |
475 | 465 | " for ID, observation in current_pair.iterrows():\n", |
476 | 466 | " x_points = [t for t in range(x_start, x_start + grp_count)]\n", |
477 | | - " y_points = observation.tolist()\n", |
| 467 | + " y_points = observation[yvar].tolist()\n", |
478 | 468 | "\n", |
479 | 469 | " if color_col is None:\n", |
480 | 470 | " slopegraph_kwargs['color'] = ytick_color\n", |
481 | 471 | " else:\n", |
482 | | - " color_key = pivoted_plot_data[color_col,\n", |
483 | | - " current_tuple[0]].loc[ID]\n", |
| 472 | + " color_key = observation[color_col][0]\n", |
484 | 473 | " if isinstance(color_key, str) == True:\n", |
485 | 474 | " slopegraph_kwargs['color'] = plot_palette_raw[color_key]\n", |
486 | 475 | " slopegraph_kwargs['label'] = color_key\n", |
|
0 commit comments