Skip to content

-R auto in subplot is not per pannel.  #3520

Closed

Description

@joa-quim

Running this shows two issues.
1- In first panel -R is auto computed but that same -R is applied to second panel
2- minor issue, the -R estimate is an exact computation, tight in Matlab parlance but that is not very nice. Compare with what is obtained with the Julia wrapper

gmt begin tales png
	gmt subplot begin 2x1 -Fs8c/4c
		gmt plot ds1.dat -W0.4 -Ba -c0,0
		gmt plot ds2.dat -W0.5 -Ba -c1,0
	gmt subplot end
gmt end show

data.zip
tales

the julia version (more things but the essential are the limits)
GMTplot

Activity

  1. PaulWessel commented on Jun 22, 2020

    @PaulWessel
    Contributor

    So what should our rule be here: Clearly, in panels a data-derived -R should only apply to that panel. So I guess the same should be true for figures? If you start off with a plot call with no -R you get a -R from the data. Subsequent overlays must inherit that one of course. But a new figure should not. So I think that is a clear rule, yes?
    We have both exact (your tight) and approx options for this. Not sure what the default is (your example suggests exact), but we could reconsider that.

  2. joa-quim commented on Jun 22, 2020

    @joa-quim
    MemberAuthor

    Yes, each figure should get its own -R.
    Approx -R looks nicer then tight.

    And that title font also looks too heavy

  3. PaulWessel commented on Jun 22, 2020

    @PaulWessel
    Contributor

    Seems like the approx R should go with datasets and the exact R goes with grids , unless the user uses -R

  4. joa-quim commented on Jun 22, 2020

    @joa-quim
    MemberAuthor

    Agreed.

  5. PaulWessel commented on Jun 23, 2020

    @PaulWessel
    Contributor

    Hi @joa-quim and @seisman: To fix this problem I am implementing the same hierarchy of gmt.history files as we do for cpts. So a panel will create its own gmt.history file, etc. but will read from a higher hierarchical level if not found. When subplot end is called I wipe all the subplot/panel histories. Nice and clean.

    Then I ran the tests and had a a dozen or so failures. Have not looked at them all but looks like they are similar to this one (panels.sh) that fails:

    gmt begin panels ps
      gmt subplot begin 2x2 -Fs3i -M5p -A -SCb -SRl -Bwstr
        gmt basemap -R0/80/0/10
        gmt basemap -c
        gmt basemap -c
        gmt basemap -c
      gmt subplot end
    gmt end show
    
    

    The problem, of course, is that the first panel sets its own -R and there is nothing set for the other panels. So we get no -R messages. The correct way is this:

    gmt begin panels ps
      gmt subplot begin 2x2 -Fs3i -M5p -A -SCb -SRl -Bwstr -R0/80/0/10
        gmt basemap
        gmt basemap -c
        gmt basemap -c
        gmt basemap -c
      gmt subplot end
    gmt end show
    

    I think we must declare a bug in the first version of this since otherwise we have no recourse. Given the example above (which works fine now) we must insist on a hierarchy of region settings. So the answer is to fix the scripts. Agree?

  6. joa-quim commented on Jun 23, 2020

    @joa-quim
    MemberAuthor

    Yes, seems right to apply the same logic.

  7. seisman commented on Jun 23, 2020

    @seisman
    Member

    Yes, it makes more sense to me. I think we need to add a section in the cookbook explain how the history, cpt and gmt.conf work in modern mode.

  8. PaulWessel commented on Jun 23, 2020

    @PaulWessel
    Contributor

    Apart from some issue with insets (which I did not test or debug yet), the rest are like the one above, including GMT gallery examples 14 16 18. While this is annoying, I think it would be a mistake to try to maintain that broken syntax going forward, as we would effectively have to competing systems:

    1. A panel must set its own -R if not is provided by the subplot call
    2. A panel will inherit the previous -R from the previous panel if not set

    I don't think we can have both. The only scheme I can see would be this:

    If no subplot common region is set, then the region of a panel is determined by decisions in this order

    1. A specific -R given to that panel
    2. Determine it automatically from given data sets or grids
    3. If none, then get the most recent panel setting if available
    4. Failure

    I am not sure how this would be implemented but perhaps there is a way.
    I think if we could do this then we solve both the data-rpoblem above as well as avoid the failures I reported. THoughs?

  9. PaulWessel commented on Jun 23, 2020

    @PaulWessel
    Contributor

    Note this would violate the scheme we use for CPTs since we never fish a panel cpt from another panel. I think fixing the 12 failing scripts is better.

  10. seisman commented on Jun 23, 2020

    @seisman
    Member

    I'd like to see the same scheme for CPT, history, and even gmt.conf. A uniform scheme is easier to document, and users don't have to remember how CPT and history work differently.

  11. joa-quim commented on Jun 23, 2020

    @joa-quim
    MemberAuthor

    It's not exactly like the cpt. For data we have the auto -R, which we do not do for cpts. But now I'm a bit confused, you say

    If no subplot common region is set, then the region of a panel is determined by decisions in this order
    
       1. A specific -R given to that panel
       2. Determine it automatically from given data sets or grids
    

    but what when a common -R is set? Will (2) automatic -R not be set? I would say it should but then what good a common -R is for?

  12. seisman commented on Jun 23, 2020

    @seisman
    Member

    We have default cpt, geo for earth relief and turbo for all other grids, just like the auto -R, right?

  13. joa-quim commented on Jun 23, 2020

    @joa-quim
    MemberAuthor

    Well, in a way yes but it's only for grids whilst the -R is for grids and data.
    We also never fished cpts between figures but we always did that for -R between figures in classic mode.
    I'm not saying that we should not go to the strict rule but the situation has nuances. I'm trying to imagine a situation where one would want to inherit the exact -R of a previous panel and not being allowed to do so. Accept a plain -R here (case (3))?

  14. PaulWessel commented on Jun 23, 2020

    @PaulWessel
    Contributor

    Cannot accept a plain -R as that is classic syntax and immediately triggers an error. We are talking about scope here for history, cpt, settings. I agree with @seisman they need to have uniform rules. In MATLAB, subplot panel 2 does not inherit the region in panel 1. It auto-scales immediately and you have to set axis if you want to have a special region. I don't know how it works in matplotlib but you guys know. Is there inheritance across panels?

  15. PaulWessel commented on Jun 23, 2020

    @PaulWessel
    Contributor

    I should say it will behave like a MATLAB provided you plot some data. But we have lots of places where we call basemap and then there is not data. I think if you want a common region for a bunch of panels then you set it on the subplot begin command and it stays. I am not sure if matplotlib has that feature - I dont think MATLAB does since there is no master-subplot command.

  16. joa-quim commented on Jun 23, 2020

    @joa-quim
    MemberAuthor

    I know almost nothing of mapplotlib but one thing I know is that in one of its modes it imitates closely the Matlab syntax.

  17. PaulWessel commented on Jun 23, 2020

    @PaulWessel
    Contributor

    And MATLAB expects to plot something (there is no basemap) except axis. So when you say subplot (r,c,p) you get a basemap from 0/1/0/1 and then you must change that by plotting or using axis. I know of no way to set up an axis call to make all the subplot have the same range. From MATLAB central it is painful to see: https://www.mathworks.com/matlabcentral/answers/412592-set-same-xlim-for-all-subplots

  18. PaulWessel commented on Jun 23, 2020

    @PaulWessel
    Contributor

    I like the idea of doing this for gmt.conf as well. So a gmt set for a subplot panel only applies to that panel, while one set before subplot applies to all of them.

  19. PaulWessel commented on Jun 23, 2020

    @PaulWessel
    Contributor

    The way a gmt.conf hierarchy would work is similar to the cpt: If, at a particular hierarchical level, there is a gmt.conf (e.g., gmt.conf.0.panel.0-1 then we read that, else we read the one higher up, all the way up to the session. When gmt.conf is written (due to a gmt set command) it shall write at its hierarchical level. So inside subplots, gmt set calls should not contaminate the whole figure. This would make the conf, history, and cpt consistent and follow the same rules, even if we have to claim we have "buts" and hence not implementing backwards compatible solutions for these mistakes. I think this is your view as well, @seisman?

  20. seisman commented on Jun 23, 2020

    @seisman
    Member

    Yes.

  21. PaulWessel commented on Jun 23, 2020

    @PaulWessel
    Contributor

    Also need to point out that there would no longer be a gmt.history file since you cannot create a history without it being for a particular figure, so gmt.history.0 is the highest practical level of actual files. But there can be session-level gmt.conf and gmt.cpt since the commands that create them do not start a figure.

  22. seisman commented on Jun 23, 2020

    @seisman
    Member

    Also need to point out that there would no longer be a gmt.history file since you cannot create a history without it being for a particular figure

    I thought some non-plotting commands also write to gmt.history. Does grdcut writes to history? Is it a session-level history?

    gmt begin 
    gmt grdcut @earth_relief_01d -R0/20/0/20
    gmt figure Fig1 pdf
    gmt plot ...
    gmt end show
    
  23. PaulWessel commented on Jun 23, 2020

    @PaulWessel
    Contributor

    Yes, I think you are right. OK, that is fine. I will do all the levels anyway.

  24. PaulWessel commented on Jun 27, 2020

    @PaulWessel
    Contributor

    The script below works, showing that the grdcut command sets a (grid) region that is picked up by the plot command:

    gmt begin 
    gmt grdcut @earth_relief_01d -R0/20/0/20 -Gt.grd
    gmt figure Fig1 pdf
      echo 10 10 | gmt plot -Sc0.5c -Gred -B
    gmt end show
    

    So we can close this issue I think? Can move the grdcut inside the figure, no difference.

  25. seisman commented on Jun 27, 2020

    @seisman
    Member

    Yes to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions