MCPcopy Create free account
hub / github.com/FlashSampling/FlashSampling / plot

Function plot

benchmarking/plot_bsz_sweep_runtime.py:109–197  ·  view source on GitHub ↗
(
    df: pd.DataFrame,
    out_path: Path,
    fmt: str,
    y_col: str,
    y_label: str,
    y_cap: float | None = None,
    log_y: bool = False,
    style: str = "line",
)

Source from the content-addressed store, hash-verified

107
108
109def plot(
110 df: pd.DataFrame,
111 out_path: Path,
112 fmt: str,
113 y_col: str,
114 y_label: str,
115 y_cap: float | None = None,
116 log_y: bool = False,
117 style: str = "line",
118) -> plt.Figure:
119 methods = list(df["method"].unique())
120
121 palette = {m: PROVIDER_COLORS[m] for m in methods}
122 fig, ax = plt.subplots()
123
124 if style == "bar":
125 sns.barplot(
126 df,
127 x="bsz",
128 y=y_col,
129 hue="method",
130 hue_order=methods,
131 palette=palette,
132 ax=ax,
133 )
134 hatches = _apply_hatches(ax, methods)
135 if y_cap is not None:
136 ax.set_ylim(0, y_cap)
137 for container in ax.containers:
138 for bar in container:
139 if bar.get_height() > y_cap:
140 true_val = bar.get_height()
141 bar.set_height(y_cap)
142 bx = bar.get_x() + bar.get_width() / 2
143 ax.text(
144 bx,
145 y_cap * 1.01,
146 f"{true_val:.0f}\u00b5s",
147 ha="center",
148 va="bottom",
149 fontsize=9,
150 fontweight="bold",
151 clip_on=False,
152 )
153 sns.move_legend(ax, "upper center", title="Method", bbox_to_anchor=(0.5, 1.35), ncol=1)
154 for handle, hatch in zip(ax.get_legend().legend_handles, hatches):
155 handle.set_hatch(hatch)
156 ax.set_xticks(ax.get_xticks(), labels=df["bsz"].unique().astype(int))
157 else:
158 for method in methods:
159 mdf = df.query("method == @method")
160 ax.plot(
161 mdf["bsz"],
162 mdf[y_col],
163 color=PROVIDER_COLORS[method],
164 marker=PROVIDER_MARKERS.get(method, "o"),
165 label=method,
166 linewidth=2,

Callers 1

mainFunction · 0.85

Calls 1

_apply_hatchesFunction · 0.85

Tested by

no test coverage detected