plotnine
plotnine copied to clipboard
Having trouble applying arrowstyle in adjust_text
def plot_leagues_ratings(
df: pl.DataFrame, filename: Union[Path, str], year: int, x_size: int, y_size: int
):
title = f"Rating ({year})"
df = df.with_columns(pl.lit(0).alias("dummy"))
df = df.to_pandas()
df["League"] = pd.Categorical(
df["League"], categories=["LCK", "LPL", "LEC", "LCS"], ordered=True
)
arrow_style = dict(arrowstyle="-", lw=0.5)
p = (
p9.ggplot(df, mapping=p9.aes(x="dummy", y="Elo"))
+ p9.facet_grid(". ~ League")
+ p9.scale_x_continuous(breaks=[0])
+ p9.labs(title=title)
+ p9.theme_bw()
+ p9.theme(
plot_title=p9.element_text(face="bold", size=18),
legend_key=p9.element_blank(),
legend_position="none",
axis_title_x=p9.element_blank(),
axis_title_y=p9.element_blank(),
axis_text_x=p9.element_blank(),
)
+ p9.geom_point(shape="_", size=3)
+ p9.geom_text(
p9.aes(label="Team"),
data=df,
adjust_text={
"expand_points": (2, 2),
"expand_text": (2, 2),
"arrowprops": arrow_style,
},
)
)
p.save(filename=str(filename), width=x_size, height=y_size, dpi=300)
The code above produces following figure:

It seems that arrowprops is applied to the first category only. The data to reproduce this is here:
You can then read the dataframe with:
import polars as pl
df = pl.read_csv("2019.csv")