Nixtla / utilsforecast

https://nixtlaverse.nixtla.io/utilsforecast
Apache License 2.0
42 stars 7 forks source link

Max width in plot function #110

Closed MaickelHubner closed 2 months ago

MaickelHubner commented 2 months ago

What happened + What you expected to happen

The plot function uses a width of 2400 on large screens and on small screens 1600. Therefore, using "pytest --mpl" to compare the images gives an error:

Error: Image dimensions did not match. Expected shape: (350, 1600) /var/folders/nq/cgfjk1bj4f1cbtx1dznwsyxw0000gn/T/tmpjk6e2upo/tests.forecast.test_plot_df/baseline.png Actual shape: (350, 2400) /var/folders/nq/cgfjk1bj4f1cbtx1dznwsyxw0000gn/T/tmpjk6e2upo/tests.forecast.test_plot_df/result.png

I need a way to set the size (width) of the generated graph regardless of the screen size used.

Versions / Dependencies

nixtla==0.5.0

Reproduction script

def plot_df(): return nixtla_client.plot(...)

@pytest.mark.mpl_image_compare def test_plot_df(): fig = plot_df(...) return fig

Issue Severity

High: It blocks me from completing my task.

jmoralez commented 2 months ago

Hey. We've thought of allowing users to create the matplotlib/plotly figure and provide that so that we only add the plots, would that solve your issue? i.e. the code would be something like:

fig, ax = plt.subplots(your_settings)
nixtla_client.plot(..., ax=ax)
MaickelHubner commented 2 months ago

Yeah...that would work for me 👍

jmoralez commented 2 months ago

The plot method of the NixtlaClient is just a wrapper over utilsforecast.plotting.plot_series, which will have the ax argument in the next release. You can use that one instead.

MaickelHubner commented 2 months ago

Could the ax parameter be included in the plot function, too, and passed to plot_series? That way, I won't need to duplicate the code in plot to call plot_series.