Reputation: 1
I'm doing some research for my job and I added a categorical column with True/False values, so the size of the DataFrame doubled.
In doing so, the sizes of the plots shrank, despite nothing else aside from the number of rows changing.
This is the FacetGrid before adding that column
before new column
And after...
after new column
I'm using a util function that does all the stylizing for me, so this is the code snippet:
timeseries_rel(super_comp[super_comp['variable'] == 'ETof'], row='name', col='match_window', y='value', hue='aligned', style='match_variable',
errorbar=('pi', 50), estimator=np.median, as_percent=True, twin_y='value_old', aspect=2,
facet_kws={'sharey': 'row', 'sharex': True, 'margin_titles': True},
title_template={"col_template":"Match Window: {col_name} Days", "row_template":"{row_name}"},
title="Interquartile ETof Field Metrics w/ Old Version Reference (n=50)");
This is how that util function is defined
def timeseries_rel(
data,
*,
y,
twin_y=None,
plot="rel",
col=None,
row=None,
hue=None,
kind="line",
refline=None,
title="",
ylabel="",
as_percent=False,
tighten=False,
errorbar=None,
export_img: bool | str = None,
title_template={},
**kwargs,
):
match plot:
case "rel":
rel = sns.relplot(
data=data,
x="forecasting_date",
y=y,
col=col,
row=row,
hue=hue,
kind=kind,
errorbar=errorbar,
**kwargs,
)
case "dis":
rel = sns.displot(
data=data, x=y, col=col, row=row, hue=hue, kind=kind, **kwargs
)
case "cat":
rel = sns.catplot(
data=data,
x="forecasting_date",
y=y,
col=col,
row=row,
hue=hue,
kind=kind,
errorbar=errorbar,
**kwargs,
)
case "lm":
rel = sns.lmplot(
data=data,
x="forecasting_date",
y=y,
col=col,
row=row,
hue=hue,
kind=kind,
errorbar=errorbar,
**kwargs,
)
case _:
raise Exception("Not a valid plot type.")
# Relabel y axis
if ylabel:
rel.set_ylabels(ylabel)
# Relabel x axis
rel.tick_params(axis="x", rotation=90)
plt.suptitle(title, y=1.02)
rel.set_titles(**title_template)
if twin_y:
for row_col, ax in rel.axes_dict.items():
bx = ax.twinx()
locator = data[(data[row] == row_col[0]) & (data[col] == row_col[1])]
sns.lineplot(
locator,
x="forecasting_date",
y=twin_y,
estimator=np.median,
errorbar=None,
ax=bx,
color='k',
ls=':',
)
bx.tick_params(
left=False,
right=False,
labelleft=False,
labelright=False,
)
bx.set_ylabel('')
bx.set(ylim=ax.get_ylim())
bx.grid(None)
if as_percent is True:
for ax in rel.axes.flat:
ax.yaxis.set_major_formatter(mtick.PercentFormatter(1.0))
if plot != "dis":
rel.set_xlabels("Forecasting Date")
for ax in rel.axes.flat:
ax.xaxis.set_major_formatter(mdates.DateFormatter("%B"))
if tighten:
rel.figure.subplots_adjust(wspace=0, hspace=0.1)
if refline:
rel.refline(**refline)
if type(export_img) is bool and export_img is True:
rel.savefig(
fname=f"../images/{str(title)}"
)
elif type(export_img) is str:
rel.savefig(
fname=f"../images/{export_img}"
)
return rel
I figured the twin_y parameter was causing this but removing that keyword didn't make any change.
Upvotes: 0
Views: 15