Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing matplotlib arguments to plot.timeseries() #463

Open
FrejaTerpPetersen opened this issue Oct 29, 2024 · 5 comments
Open

Passing matplotlib arguments to plot.timeseries() #463

FrejaTerpPetersen opened this issue Oct 29, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@FrejaTerpPetersen
Copy link

FrejaTerpPetersen commented Oct 29, 2024

I would like to be able to choose colors and linestyles of the timeseries plot in modelskil. I use the following code:
image

cc2["Drogden"] is a modelskill comparer.

Where I essentially would like to do something along the lines of:

(cc2["Drogden"].sel(start="10-05-1997",end="10-17-1997")).plot.timeseries(ax=ax, col=pal)

where pal is a list holding the matplotlib color codes. Similarly for linestyles.

@ecomodeller
Copy link
Member

@jsmariegaard
Copy link
Member

I suppose we could forward the formatting to pandas https://pandas.pydata.org/pandas-docs/stable/user_guide/visualization.html#general-plot-style-arguments

Can you alter individual line styles and colors in this way?

Alternatively, I still have a dream of each model has it's own color attribute (actually it already has but it is just not used). See also top of the backlog list: https://github.com/orgs/DHI/projects/32 this does not include the linestyle though...

@ecomodeller
Copy link
Member

import pandas as pd

data = {'Model A': [10, 20, 30, 40, 50],
        'Model B': [5, 10, 15, 20, 25],
        'Observations': [1, 2, 3, 4, 5]}

df = pd.DataFrame(data)
df.plot(style=['-', 'r-', 'g-o'])

image

@jsmariegaard jsmariegaard added the enhancement New feature or request label Nov 5, 2024
@jsmariegaard
Copy link
Member

@FrejaTerpPetersen would you like to give this a try. You can open a PR and we can help you :-)

I would suggest this API:

 cc.plot.timeseries(style=['-', 'r-', 'g-o'])

as it is consistent with the pandas API. You would need to add the new argument to

- you will need to add a test to in https://github.com/DHI/modelskill/blob/main/tests/test_timeseries_plot.py that uses the new argument.

I guess a main design decision here is to decide on the allowed length of the style-list (should it be number-of-models, numer-of-models-plus-obs, or any of the two)... But that we can discuss in the PR.

@FrejaTerpPetersen
Copy link
Author

I'll try :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants