|
325 | 325 | " # Legend kwargs.\n", |
326 | 326 | " default_legend_kwargs = {\n", |
327 | 327 | " \"loc\": \"upper left\", \n", |
328 | | - " \"frameon\": False\n", |
| 328 | + " \"frameon\": False,\n", |
329 | 329 | " }\n", |
330 | 330 | " if plot_kwargs[\"legend_kwargs\"] is None:\n", |
331 | 331 | " legend_kwargs = default_legend_kwargs\n", |
|
1163 | 1163 | " )\n", |
1164 | 1164 | "\n", |
1165 | 1165 | "\n", |
1166 | | - "def show_legend(legend_labels, legend_handles, rawdata_axes, contrast_axes, float_contrast, show_pairs, horizontal, legend_kwargs):\n", |
| 1166 | + "def show_legend(legend_labels, legend_handles, rawdata_axes, contrast_axes, table_axes, float_contrast, show_pairs, horizontal, legend_kwargs, table_kwargs):\n", |
1167 | 1167 | " \"\"\"\n", |
1168 | 1168 | " Show the legend for the plotter function.\n", |
1169 | 1169 | "\n", |
|
1177 | 1177 | " The raw data axes.\n", |
1178 | 1178 | " contrast_axes : object (Axes)\n", |
1179 | 1179 | " The contrast axes.\n", |
| 1180 | + " table_axes : object (Axes)\n", |
| 1181 | + " The table axes.\n", |
1180 | 1182 | " float_contrast : bool\n", |
1181 | 1183 | " A boolean flag to determine if the plot is GA or Cumming format.\n", |
1182 | 1184 | " show_pairs : bool\n", |
|
1193 | 1195 | " pd.Series(legend_handles, dtype=\"object\").loc[unique_idx]\n", |
1194 | 1196 | " ).tolist()\n", |
1195 | 1197 | "\n", |
1196 | | - " if len(legend_handles_unique) > 0:\n", |
| 1198 | + " # Location of the legend\n", |
| 1199 | + " if \"bbox_to_anchor\" not in legend_kwargs.keys():\n", |
1197 | 1200 | " if horizontal:\n", |
1198 | | - " axes_with_legend = rawdata_axes\n", |
1199 | | - " # bta = (0.8, 0.8)\n", |
1200 | | - " leg = axes_with_legend.legend(\n", |
1201 | | - " legend_handles_unique,\n", |
1202 | | - " legend_labels_unique,\n", |
1203 | | - " handlelength=0.5,\n", |
1204 | | - " **legend_kwargs\n", |
1205 | | - " )\n", |
1206 | | - " if show_pairs:\n", |
1207 | | - " for line in leg.get_lines():\n", |
1208 | | - " line.set_linewidth(3)\n", |
| 1201 | + " bta = (1,1)\n", |
1209 | 1202 | " else:\n", |
1210 | 1203 | " if float_contrast:\n", |
1211 | | - " axes_with_legend = contrast_axes\n", |
1212 | | - " if show_pairs:\n", |
1213 | | - " bta = (2.00, 1.02)\n", |
1214 | | - " else:\n", |
1215 | | - " bta = (1.5, 1.02)\n", |
| 1204 | + " bta = (2.00, 1.02) if show_pairs else (1.5, 1.02)\n", |
1216 | 1205 | " else:\n", |
1217 | | - " axes_with_legend = rawdata_axes\n", |
1218 | | - " if show_pairs:\n", |
1219 | | - " bta = (1.02, 1.0)\n", |
1220 | | - " else:\n", |
1221 | | - " bta = (1.0, 1.0)\n", |
1222 | | - " leg = axes_with_legend.legend(\n", |
1223 | | - " legend_handles_unique,\n", |
1224 | | - " legend_labels_unique,\n", |
1225 | | - " bbox_to_anchor=bta,\n", |
1226 | | - " **legend_kwargs\n", |
1227 | | - " )\n", |
1228 | | - " if show_pairs:\n", |
1229 | | - " for line in leg.get_lines():\n", |
1230 | | - " line.set_linewidth(3.0)\n", |
| 1206 | + " bta = (1.02, 1.0) if show_pairs else (1.0, 1.0)\n", |
| 1207 | + " legend_kwargs.update({'bbox_to_anchor': bta})\n", |
| 1208 | + "\n", |
| 1209 | + " # Pick the ax to plot\n", |
| 1210 | + " if horizontal:\n", |
| 1211 | + " if table_kwargs['show']:\n", |
| 1212 | + " axes_with_legend = table_axes\n", |
| 1213 | + " else:\n", |
| 1214 | + " axes_with_legend = contrast_axes\n", |
| 1215 | + " elif float_contrast:\n", |
| 1216 | + " axes_with_legend = contrast_axes\n", |
| 1217 | + " else:\n", |
| 1218 | + " axes_with_legend = rawdata_axes\n", |
| 1219 | + "\n", |
| 1220 | + " # Plot the legend\n", |
| 1221 | + " if len(legend_handles_unique) > 0:\n", |
| 1222 | + " leg = axes_with_legend.legend(\n", |
| 1223 | + " legend_handles_unique,\n", |
| 1224 | + " legend_labels_unique,\n", |
| 1225 | + " handlelength=0.5,\n", |
| 1226 | + " **legend_kwargs\n", |
| 1227 | + " )\n", |
| 1228 | + " if show_pairs:\n", |
| 1229 | + " for line in leg.get_lines():\n", |
| 1230 | + " line.set_linewidth(3.0)\n", |
1231 | 1231 | " \n", |
1232 | 1232 | "def Gardner_Altman_Plot_Aesthetic_Adjustments(effect_size_type, plot_data, xvar, yvar, current_control, current_group,\n", |
1233 | 1233 | " rawdata_axes, contrast_axes, results, current_effsize, is_paired, one_sankey,\n", |
|
0 commit comments