|
19 | 19 | "The `nac` package itself is completely independent." |
20 | 20 | ] |
21 | 21 | }, |
| 22 | + { |
| 23 | + "cell_type": "markdown", |
| 24 | + "metadata": {}, |
| 25 | + "source": [ |
| 26 | + "If you are using VScode, add this option to your `.vscode/settings.json` file.\n", |
| 27 | + "```json\n", |
| 28 | + "{\n", |
| 29 | + " \"jupyter.notebookFileRoot\": \"${workspaceFolder}\"\n", |
| 30 | + "}\n", |
| 31 | + "```" |
| 32 | + ] |
| 33 | + }, |
22 | 34 | { |
23 | 35 | "cell_type": "code", |
24 | | - "execution_count": null, |
| 36 | + "execution_count": 119, |
25 | 37 | "metadata": {}, |
26 | 38 | "outputs": [], |
27 | 39 | "source": [ |
|
76 | 88 | }, |
77 | 89 | { |
78 | 90 | "cell_type": "code", |
79 | | - "execution_count": null, |
| 91 | + "execution_count": 120, |
80 | 92 | "metadata": {}, |
81 | 93 | "outputs": [], |
82 | 94 | "source": [ |
|
89 | 101 | }, |
90 | 102 | { |
91 | 103 | "cell_type": "code", |
92 | | - "execution_count": null, |
| 104 | + "execution_count": 121, |
93 | 105 | "metadata": {}, |
94 | 106 | "outputs": [], |
95 | 107 | "source": [ |
96 | 108 | "# https://jwalton.info/Embed-Publication-Matplotlib-Latex/\n", |
97 | 109 | "import matplotlib.backends.backend_pgf\n", |
98 | 110 | "\n", |
| 111 | + "DEFAULT_FIG_WIDTH = 398.33858\n", |
99 | 112 | "\n", |
100 | 113 | "def fig_size(\n", |
101 | | - " width: float = 398.33858,\n", |
| 114 | + " width: float = DEFAULT_FIG_WIDTH,\n", |
102 | 115 | " fraction: float = 2,\n", |
103 | 116 | " subplots: Tuple[int,int] = (1, 1),\n", |
104 | 117 | " ):\n", |
|
117 | 130 | " fig_dim: tuple\n", |
118 | 131 | " Dimensions of figure in inches\n", |
119 | 132 | " \"\"\"\n", |
| 133 | + "\n", |
120 | 134 | " # Width of figure (in pts)\n", |
121 | 135 | " fig_width_pt = width * fraction\n", |
122 | 136 | " # Convert from pt to inches\n", |
|
131 | 145 | " # Figure height in inches\n", |
132 | 146 | " fig_height_in = fig_width_in * golden_ratio * (subplots[0] / subplots[1])\n", |
133 | 147 | "\n", |
| 148 | + " if subplots == (1, 1):\n", |
| 149 | + " fig_width_in *= 3/4\n", |
| 150 | + " fig_height_in *= 2/5\n", |
| 151 | + "\n", |
134 | 152 | " return (fig_width_in, fig_height_in)\n", |
135 | 153 | "\n", |
136 | 154 | "\n", |
|
173 | 191 | }, |
174 | 192 | { |
175 | 193 | "cell_type": "code", |
176 | | - "execution_count": null, |
| 194 | + "execution_count": 122, |
177 | 195 | "metadata": {}, |
178 | 196 | "outputs": [], |
179 | 197 | "source": [ |
|
249 | 267 | }, |
250 | 268 | { |
251 | 269 | "cell_type": "code", |
252 | | - "execution_count": null, |
| 270 | + "execution_count": 124, |
253 | 271 | "metadata": {}, |
254 | 272 | "outputs": [], |
255 | 273 | "source": [ |
| 274 | + "\n", |
256 | 275 | "def _group_and_plot(\n", |
257 | 276 | " df: pd.DataFrame,\n", |
258 | 277 | " with_log: bool,\n", |
259 | 278 | " axs: List[plt.Axes],\n", |
| 279 | + " aggregations: List[Literal[\"mean\", \"median\", \"3rd quartile\"]],\n", |
260 | 280 | " x_column: Literal[\"vertex_no\", \"monochromatic_classes_no\"],\n", |
261 | 281 | " based_on: Literal[\"relabel\", \"split\", \"merging\"],\n", |
262 | 282 | " value_columns: List[Literal[\"nac_first_mean_time\", \"nac_all_mean_time\"]],\n", |
263 | 283 | "):\n", |
264 | | - " aggregations = [\"mean\", \"median\", \"3rd quartile\"]\n", |
265 | 284 | " df = df.loc[:, [x_column, based_on, *value_columns]]\n", |
266 | 285 | " groupped = df.groupby([x_column, based_on])\n", |
267 | 286 | "\n", |
|
295 | 314 | " ax.set_yscale(\"log\")\n", |
296 | 315 | " ax.xaxis.set_major_locator(MaxNLocator(integer=True))\n", |
297 | 316 | " ax.set_xlabel(rename_based_on[x_column])\n", |
298 | | - " ax.legend(loc='upper left')\n", |
| 317 | + "\n", |
| 318 | + "\n", |
| 319 | + "\n", |
| 320 | + " if len(aggregations) == 1:\n", |
| 321 | + " ax.legend(\n", |
| 322 | + " bbox_to_anchor=(1.0, 1.0),\n", |
| 323 | + " loc='upper left',\n", |
| 324 | + " )\n", |
| 325 | + " else:\n", |
| 326 | + " ax.legend(\n", |
| 327 | + " loc='upper left',\n", |
| 328 | + " )\n", |
299 | 329 | "\n", |
300 | 330 | "def plot_frame(\n", |
301 | 331 | " title: str,\n", |
|
314 | 344 | " # \"merging\",\n", |
315 | 345 | " \"split_merging\",\n", |
316 | 346 | " ],\n", |
317 | | - " ops_aggregation = [\"mean\", \"median\",], # \"3rd quartile\",\n", |
| 347 | + " # ops_aggregation = [\"mean\", \"median\",], # \"3rd quartile\",\n", |
| 348 | + " ops_aggregation = [\"mean\"], # \"3rd quartile\",\n", |
318 | 349 | ") -> List[Figure]:\n", |
319 | 350 | " print(f\"Plotting {df.shape[0]} records...\")\n", |
320 | 351 | " figs = []\n", |
|
337 | 368 | " ncols = len(ops_aggregation)\n", |
338 | 369 | " fig = figure(\n", |
339 | 370 | " nrows * ncols,\n", |
340 | | - " figsize=fig_size(subplots=(nrows, ncols)),\n", |
| 371 | + " figsize=fig_size(\n", |
| 372 | + " # width=DEFAULT_FIG_WIDTH if len(ops_aggregation) > 1 else DEFAULT_FIG_WIDTH * 3/4,\n", |
| 373 | + " subplots=(nrows, ncols),\n", |
| 374 | + " ),\n", |
341 | 375 | " layout='constrained',\n", |
342 | 376 | " )\n", |
343 | 377 | " title_detail = \" | \".join(title_rename[value_column] for value_column in value_columns)\n", |
|
349 | 383 | " axs = [\n", |
350 | 384 | " fig.add_subplot(nrows, ncols, i+ncols*row+1)\n", |
351 | 385 | " for i in range(len(ops_aggregation))]\n", |
352 | | - " _group_and_plot(local_df, with_log, axs, x_column, based_on, value_columns)\n", |
| 386 | + " _group_and_plot(local_df, with_log, axs, ops_aggregation, x_column, based_on, value_columns)\n", |
353 | 387 | " row += 1\n", |
354 | 388 | " return figs\n", |
355 | 389 | "\n", |
|
372 | 406 | }, |
373 | 407 | { |
374 | 408 | "cell_type": "code", |
375 | | - "execution_count": null, |
| 409 | + "execution_count": 126, |
376 | 410 | "metadata": {}, |
377 | 411 | "outputs": [], |
378 | 412 | "source": [ |
|
386 | 420 | }, |
387 | 421 | { |
388 | 422 | "cell_type": "code", |
389 | | - "execution_count": null, |
| 423 | + "execution_count": 127, |
390 | 424 | "metadata": {}, |
391 | 425 | "outputs": [], |
392 | 426 | "source": [ |
|
459 | 493 | }, |
460 | 494 | { |
461 | 495 | "cell_type": "code", |
462 | | - "execution_count": null, |
| 496 | + "execution_count": 130, |
463 | 497 | "metadata": {}, |
464 | 498 | "outputs": [], |
465 | 499 | "source": [ |
|
471 | 505 | " value_columns: List[Literal[\"nac_first_mean_time\", \"nac_all_mean_time\"]],\n", |
472 | 506 | " aggregation: Literal[\"mean\", \"median\", \"3rd quartile\"],\n", |
473 | 507 | " legend_rename_dict: Dict[str, str] = {},\n", |
| 508 | + " legend_outside: bool = False,\n", |
474 | 509 | "):\n", |
475 | 510 | " df = df.loc[:, [x_column, *value_columns]]\n", |
476 | 511 | " groupped = df.groupby([x_column])\n", |
|
496 | 531 | " ax.xaxis.set_major_locator(MaxNLocator(integer=True))\n", |
497 | 532 | " ax.set_xlabel(rename_based_on[x_column])\n", |
498 | 533 | " handles, labels = ax.get_legend_handles_labels()\n", |
499 | | - " ax.legend(\n", |
| 534 | + " if legend_outside:\n", |
| 535 | + " ax.legend(\n", |
500 | 536 | " handles,\n", |
501 | 537 | " [legend_rename_dict[l] for l in labels],\n", |
502 | | - " # loc = 'upper left',\n", |
503 | | - " )\n", |
| 538 | + " bbox_to_anchor=(1.0, 1.0),\n", |
| 539 | + " loc='upper left',\n", |
| 540 | + " )\n", |
| 541 | + " else:\n", |
| 542 | + " ax.legend(\n", |
| 543 | + " handles,\n", |
| 544 | + " [legend_rename_dict[l] for l in labels],\n", |
| 545 | + " # loc = 'upper left',\n", |
| 546 | + " )\n", |
504 | 547 | "\n", |
505 | 548 | "def plot_is_NAC_coloring_calls(\n", |
506 | 549 | " df: pd.DataFrame,\n", |
|
567 | 610 | " # [\"inv_edge_no\", \"inv_triangle_component_no\", \"inv_monochromatic_class_no\", \"inv_nac_all_check_cycle_mask\", \"inv_nac_all_check_is_NAC\", ],\n", |
568 | 611 | " # [\"new_edge_no\", \"new_triangle_component_no\", \"new_monochromatic_class_no\", \"new_nac_all_check_cycle_mask\" ],\n", |
569 | 612 | " ]\n", |
570 | | - " ops_aggregation = [\"mean\", \"median\", ] # \"3rd quartile\",\n", |
| 613 | + " # ops_aggregation = [\"mean\", \"median\", ] # \"3rd quartile\",\n", |
| 614 | + " ops_aggregation = [\"mean\" ] # \"3rd quartile\",\n", |
571 | 615 | "\n", |
572 | 616 | " nrows = len(ops_value_groups)\n", |
573 | 617 | " ncols = len(ops_aggregation)\n", |
|
595 | 639 | " fig.add_subplot(nrows, ncols, i+ncols*row+1)\n", |
596 | 640 | " for i in range(len(ops_aggregation))]\n", |
597 | 641 | " for ax, aggregation in zip(axs,ops_aggregation):\n", |
598 | | - " _plot_is_NAC_coloring_calls_groups(title, df, ax, x_column, value_columns, aggregation, legend_rename_dict=rename_dict)\n", |
| 642 | + " _plot_is_NAC_coloring_calls_groups(title, df, ax, x_column, value_columns, aggregation, legend_rename_dict=rename_dict, legend_outside=len(ops_aggregation) <= 1)\n", |
599 | 643 | " row += 1\n", |
600 | 644 | "\n", |
601 | 645 | " return figs" |
|
633 | 677 | "name": "python", |
634 | 678 | "nbconvert_exporter": "python", |
635 | 679 | "pygments_lexer": "ipython3", |
636 | | - "version": "3.12.6" |
| 680 | + "version": "3.12.8" |
637 | 681 | } |
638 | 682 | }, |
639 | 683 | "nbformat": 4, |
|
0 commit comments