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

set plot style #150

Closed
wants to merge 4 commits into from
Closed

set plot style #150

wants to merge 4 commits into from

Conversation

daniel-caichac-DHI
Copy link
Collaborator

Hi,

I would like to change the default matplotlib style for scatter plots in order to match other plots from DHI, as now fmskill looks too different.

This is how it looks now

image

And just by changing some line colors and sizes of markers and locations, I get this, which aligns with other tools (eg MOOD plots)
image

Still not 100% identical but quite almost there at least (both plots are different data by the way)

@daniel-caichac-DHI daniel-caichac-DHI marked this pull request as ready for review December 15, 2022 13:59
@daniel-caichac-DHI
Copy link
Collaborator Author

daniel-caichac-DHI commented Dec 15, 2022

I had a spaguetti of branches so I had to make a new one only with this change :)

Copy link
Member

@ecomodeller ecomodeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. If you make a scatter plot without a table of skill scores, and the model agrees fairly well with the observations, I think it makes sense to have an easy option to place the legend inside the plot.
  2. If I change the figsize argument the legend is messed up
    image

@jsmariegaard
Copy link
Member

I am a bit hesitant about making the m_tools/MOOD style of plotting the default in FMskill. I think it would be better to have a global parameter:

fmskill.plot_style = "MOOD" 

or similar to control the look and feel of the plots.

@daniel-caichac-DHI
Copy link
Collaborator Author

@ecomodeller : I fixed the location based on fig size, now it should stay in place

@Hendrik1987
Copy link
Contributor

@jsmariegaard : Fully agree with your suggestion. However, can we get help with setting this up? :-) Or do you have a good example to adopt from?

@ecomodeller
Copy link
Member

I am a bit hesitant about making the m_tools/MOOD style of plotting the default in FMskill. I think it would be better to have a global parameter:

fmskill.plot_style = "MOOD" 

or similar to control the look and feel of the plots.

In order to get broad adoption we to make sure that fmskill is easily customizable to match the slightly different needs of various users, maybe get some inspiration configuration from pandas https://pandas.pydata.org/docs/user_guide/options.html, I think the need for customization is wider than simply the style of the plots.

@Hendrik1987
Copy link
Contributor

I guess I was wondering: Is there a quick way into this now :-)

How about we simply add .scatter(style = None) for now? Just as we have skill_table, plot_backend and maybe others. Then we can in a new PR think about which and how to replace args by global customization?

Maybe it would be even desirable to also have these customization arguments in each method, where the global customization only sets the default (maybe you want a one-off plot look different without changing the global settings)?

@daniel-caichac-DHI
Copy link
Collaborator Author

I support Hendrik's idea

Copy link
Collaborator Author

@daniel-caichac-DHI daniel-caichac-DHI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ecomodeller: I added the requested changes

@daniel-caichac-DHI
Copy link
Collaborator Author

daniel-caichac-DHI commented Dec 21, 2022

I found a way to implement this I think

@daniel-caichac-DHI
Copy link
Collaborator Author

@jsmariegaard I implemented a plot_style as wanted, so by default you get
image
and if you add fmskill.plot_style = 'MOOD' somewhere, you change the global style
image

and if the previous (default) style is preferred, the user can either restart the kernel or
image

@Hendrik1987
Copy link
Contributor

Good stuff @daniel-caichac-DHI ! Can we not set skill_table = True as default for plot_style = 'MOOD'?

@daniel-caichac-DHI
Copy link
Collaborator Author

@Hendrik1987 I think we can, I just did not think about it , let me fix it

@daniel-caichac-DHI
Copy link
Collaborator Author

image
there it is:
if style=mood and skill_table not explicitly False, then by default skill_table=True

@ecomodeller
Copy link
Member

Looks great. I am pasting in a random sample from MOOD for comparison.
image

Is the aim to get the plot with plot_style = 'MOOD' to be identical to the plot you get on MOOD?

The main difference is in the title, where the MOOD version has a lot information, are you going to include that as well, and some less important (the title says scatter plot, not sure how useful that is)?

There are some other minor differences, like x axis labels in 45 degrees and non-linear labels on the colorbar (not sure why you would want that though🙄)

@Hendrik1987
Copy link
Contributor

Hendrik1987 commented Dec 22, 2022

@ecomodeller , I don't think it needs to be 100%. But yes, it would be ultimately be the goal to have similar info in the title. But I think we need to first fix the attrs container from which the title can be constructed (as well as labels, units etc.). For now the user can use the title argument.

@jsmariegaard
Copy link
Member

FYI, I am working on a general concept for global settings in FMskill. Will make it a PR either today or tomorrow. We can then merge that first, before finishing this PR.

@daniel-caichac-DHI
Copy link
Collaborator Author

daniel-caichac-DHI commented Jan 3, 2023

Following @Hendrik1987 comments, indeed it does not need to be 100% equivalent (we would need to calculate the Peak Ratio for that as well), and as of now we can with the *kwargs control the xlabel, ylabel and title. We can even have some improvements over the MOOD plot (as in, maybe less decimals for the location, or give the location in UTM if we wanted to).

But what we don't want is to have two plots that look completely different, because then we basically cannot use FMSkill for production in combination with MOOD plots, and that's one of our goals.

@daniel-caichac-DHI
Copy link
Collaborator Author

FYI, I am working on a general concept for global settings in FMskill. Will make it a PR either today or tomorrow. We can then merge that first, before finishing this PR.

@jsmariegaard are we ok to merge this PR now???

@jsmariegaard jsmariegaard changed the title update default style set plot style Jan 11, 2023
@jsmariegaard
Copy link
Member

I finally, got around to work on the global options, they are coming along in #158 - we will merge the global options first, before finishing this PR.

@Hendrik1987 Hendrik1987 mentioned this pull request Jan 11, 2023
@jsmariegaard
Copy link
Member

@daniel-caichac-DHI #158 have now been merged - have a look at https://github.com/DHI/fmskill/blob/main/tests/test_settings.py and https://github.com/DHI/fmskill/blob/main/fmskill/plot.py on how to use. We still need to define a function fmskill.set_style() or similar to invoke a number of functions at the same time. But at least we now have a way to handle options in fmskill :)

@jsmariegaard
Copy link
Member

By the way, it may be simpler to start a new branch following the new way of specifying settings rather than solve all the merge conflicts in this one...

@daniel-caichac-DHI
Copy link
Collaborator Author

daniel-caichac-DHI commented Jan 17, 2023

sure, the amount of conflicts will make it easier to make a new branch.
Question is: how should I implement the mood style now?
I am thinking something like the following example with Q-Q label:

  • default now is register_option("plot.scatter.quantiles.label", "Q-Q", validator=settings.is_str)
  • maybe I could add something like
    if fmskill.options.style='MOOD':
    options.plot.scatter.quantiles.label="Q-Q Line 1:1 fit"
    @jsmariegaard what do you think? I already have all the values and colors/sizes of the MOOD style from this branch that I can close, question is how to implement now to get a smooth approval.

@jsmariegaard
Copy link
Member

I tried to add some examples of how to register options at the top of https://github.com/DHI/fmskill/blob/main/fmskill/plot.py (and used correspondingly inside the scatter method). That you'll need to do first for all the options you wish to change.

Then we can make a new function in the settings module. Let's call it set_plot_style() for now. This method takes a name as an argument (e.g. MOOD) and contains a dict of the changes that need to be made compared to the default settings. At the bottom of this function, you can apply the options all at once by providing the dict as an argument to fmskill.set_option().

Does it make sense?

@daniel-caichac-DHI
Copy link
Collaborator Author

daniel-caichac-DHI commented Jan 17, 2023

I am trying to understand, but if I want to have say point size=5 when using MOOD style, I assume this should be inside the set_plot_style as you say, in a dictionary, but I don't understand "what exatly" should be inside this dictionary and how we would call it later.

I think that with a single example I could set all the others params

@jsmariegaard
Copy link
Member

From the user perspective, only this will be needed:

import fmskill 
fmskill.set_plot_style("MOOD")
# do normal stuff, all plots will now have MOOD-style

As a developer, contributing a new style, you will have to check that all the things you want to change are already registered as an option. If they are, you can just go ahead and create a dictionary with those options.

In settings.py you can add this:

def set_plot_style(name:str) -> None:
    d = {}
    if name == "MOOD":
        d["plot.scatter.quantiles.markersize"] = 2.0
        d["plot.scatter.oneone_line.label"] = "1:1 (45degrees)"
        # add more here
    else: 
        raise ValueError(f"Plot style '{name}' not found (MOOD)")
    set_option(d)

@daniel-caichac-DHI daniel-caichac-DHI mentioned this pull request Jan 17, 2023
@jsmariegaard jsmariegaard deleted the default_style_update branch November 20, 2023 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants