ArtesiaWater / hydropandas

Module for loading observation data into custom DataFrames
https://hydropandas.readthedocs.io
MIT License
51 stars 10 forks source link

.plots.section_plot: better xlim's #115

Closed HMEUW closed 1 year ago

HMEUW commented 1 year ago

The observation plot of section_plot needs better xlims:

Does someone knows why the xlims are chosen by matplotlib this way? And an easy way to fix this, to achieve an elegant lower bound of the x-axis? In this example an x-limit at 1 jan 1997 is preferred, xticks are then at 1 jan every 3 or 4 years. For timeseries shorter than a few years, an exact start at tmin is better.

tmin not specified image

tmin specified image

start obs image

OnnoEbbens commented 1 year ago

In the section_plot function a line is plotted using p = ax_obs.plot(plot_df). Using this, matplotlib will pick an xlim in such a way that there is some white space before the start (and after the end) of the line. I think they do this so you can see exactly where the line starts (and ends).

When you specify tmin in the section_plot function the plof_df is sliced using plot_df = self._obj.loc[name, "obs"][tmin:tmax][cols].copy(). The plot is still created using p = ax_obs.plot(plot_df) so matplotlib will pick an xlim with some white space before the start of the sliced DataFrame.

I think the solution here is to set the xlim after the plot is created based on tmin and tmax for example: ax_obs.set_xlim(tmin, tmax).

HMEUW commented 1 year ago

Thanks for your suggestion. I will implement for the option when tmin is set. I will do some research about the chosen xlim for the plot without tmin. A 4,5 year gap is a little bit too much for me.

Today I checked wether there is some NaN data in the dataset, that might cause the 4,5 year gap. There is no NaN data.

martinvonk commented 1 year ago

closed by #116