Skip to content

Allow MAP_FRAME_TYPE=graph-origin - #6824

Merged
PaulWessel merged 16 commits into
masterfrom
centered-graph-axes
Jul 2, 2022
Merged

PaulWessel merged 16 commits into
masterfrom
centered-graph-axes

Conversation

@PaulWessel

@PaulWessel PaulWessel commented Jun 25, 2022 •

Copy link
Copy Markdown
Contributor

See #6820 for background (@gd-a). This is a test branch for exploring this possibility. There are some remaining decisions to be made (plus adding documentation), hence the WIP.

This matches the request for this command:

gmt basemap -R-20/20/-20/20 -JX5i -Bafg --MAP_FRAME_TYPE=graph-origin -png 1

yielding

1

However, if you don't select grid lines (leaving off the g or just use default -B, you get

2

where the annotations look a bit naked. If you don't want any annotations or ticks you may try -Bws (lower case turns off annotation) but ticks persist even with -Ba2f0:

3

Some possibilities:

  1. If gridlines are not specified, use grid pen to draw the axis lines where they would normally have gone (e.g., WS here). This may be preferred since depending on -R you may not be able to select a grid interval that does that.
  2. If annotations are not requested (i.e., -Bws) then honor that but also turn off tick marks
  3. Here, origin meant draw at x = 0 and y = 0, but I can imagine some joker wanting to specify the desired x and y placements. So are we talking MAP_FRAME_TYPE=graph-origin[,x/y] then, with default 0?

Finally, I can imagine some users wish to have centered annotated axes and leave out the (otherwise clobbered) zero annotation:

4

as shown in this mock-up. It would not be too hard to implement that. Do we call that MAP_FRAME_TYPE=graph-origin[,x/y] ?

See #6820 for background.  This is a test branch for exploring this possibility.  There are some remaining decisions to be made, hence the WIP.
@PaulWessel PaulWessel added the discussion Topics for longer discussion label Jun 25, 2022
@PaulWessel PaulWessel added this to the 6.5.0 milestone Jun 25, 2022
@PaulWessel
PaulWessel requested a review from a team June 25, 2022 13:15
@PaulWessel PaulWessel self-assigned this Jun 25, 2022
@joa-quim

Copy link
Copy Markdown
Member

I think only the last example, centered annotations, is of interest (that's what everybody would manually draw). If someone really wants the outside annotations, make a second call to basemap. Grid-lines is probably an exception. I can perfectly imagine the wish of centered annotations plus grid-lines

@gd-a

gd-a commented Jun 25, 2022

Copy link
Copy Markdown
Contributor

The last panel is definitely the best looking one (IMO).

4

But I'd keep the 0, especially foreseeing this remark :

but I can imagine some joker wanting to specify the desired x and y placements

After all, the "first" annotation is supposed to be easy to remove thanks to B+e option (it reminds me this BTW.

@PaulWessel

Copy link
Copy Markdown
Contributor Author

Annotating the center is asking for trouble. If one used a non 0/0 value then it double always overprint. Here is 0/0:

4

I think from all the other annotations there is no need to do something complicated at the center since those values, whatever they are, could be spelled out in a figure caption or text etc., or just inferred from the other annotations.

@PaulWessel

PaulWessel commented Jun 25, 2022 •

Copy link
Copy Markdown
Contributor Author

So, based on this limited feedback, the leading candidate is --MAP_FRAME_TYPE=graph-origin[,x/y] and it would only result in the last map as is.

@gd-a

gd-a commented Jun 25, 2022

Copy link
Copy Markdown
Contributor

What about slightly shifting the annotation ? That would solve the grid overlap too

@PaulWessel

Copy link
Copy Markdown
Contributor Author

What about slightly shifting the annotation ? That would solve the grid overlap too

This would need to involve font size, absolute values, spacing etc. It is not a fun thing to do. I think leaving it out is a good start. There is always text if people cannot figure out what those coordinates are.

@gd-a

gd-a commented Jun 25, 2022 •

Copy link
Copy Markdown
Contributor

There is always text if people cannot figure out what those coordinates are.

True. What about the B+el option ?

@PaulWessel

Copy link
Copy Markdown
Contributor Author

Well, -B+e has no knowledge of any center coordinate to skip. One can image a -B+ec but the point is that nobody would want an annotation that prints on top of the axis and the other annotation, which brings us back to the "can we just shift it a bit". There is real agony in determine "a bit".

@gd-a

gd-a commented Jun 25, 2022

Copy link
Copy Markdown
Contributor

agony

Alright alright. You're the one doing the work here 🥇

@gd-a

gd-a commented Jun 25, 2022 •

Copy link
Copy Markdown
Contributor

I'm curious about the result with this showcase :

#!/bin/bash

gmt begin test png

	vecsta=$(gmt math -Q -3 PI MUL =)
	vecsto=$(gmt math -Q 3 PI MUL =)
	vecste=$(gmt math -Q 1 32 DIV =)

        # x
	gmt math -T$vecsta/$vecsto/$vecste T -o0 = x.txt
       # y = sin(x)
	gmt math -Q x.txt SIN = y.txt 
        #y2 = A cos(x+B)
	gmt math -Q x.txt PI 3 DIV ADD COS 4 PI MUL 10 DIV MUL = y2.txt

        # Shading for red<blue
	gmt math -Q y.txt y2.txt LE 0 NAN y.txt MUL = y_c.txt
        # Shading for red>blue
	gmt math -Q y.txt y2.txt GE 0 NAN y2.txt MUL = y2_c.txt

        # All in one file (for -Sb+base option)
	paste x.txt y.txt y2.txt y_c.txt y2_c.txt > file.txt

        # Graph-paper
	gmt basemap -R-10/10/-2/2 -JX10c -Bxafpigpi -Byafg -BW+t"Relative anomaly" --MAP_FRAME_TYPE=graph-origin --MAP_GRID_PEN=lightgray
 
        # Plot sines
	gmt plot file.txt -i0,1 -Wfat,blue -l"@[\sin(x)@["
	gmt plot file.txt -i0,2 -Wfat,red -l"@[\frac{4\pi}{10}\cos(x+\frac{\pi}{3})@["

        # Plot shades
	gmt plot file.txt -i0,3,2 -Gred@90 -Sb${vecste}q+b -l"red > blue"
	gmt plot file.txt -i0,4,1 -Gblue@90 -Sb${vecste}q+b -l"red < blue"

gmt end show

@PaulWessel

PaulWessel commented Jun 25, 2022 •

Copy link
Copy Markdown
Contributor Author

Give it a try. I have updated the docs. For various reasons the syntax is

--MAP_FRAME_TYPE=graph-origin[+ox/y]

My complaints about unwanted ticks were silly since one can just select axis l and b to just get the vectors and w and s to add ticks.

@gd-a

gd-a commented Jun 25, 2022 •

Copy link
Copy Markdown
Contributor

Give it a try. I have updated the docs.

I don't see it in dev doc.

> gmt --version
6.5.0_8bbc44d_2022.06.25

> bash Untitled-1.sh
basemap [WARNING]: Bad fraction, error = 0.00128068

> > 
#!/bin/bash

gmt begin test png

	vecsta=$(gmt math -Q -3 PI MUL =)
	vecsto=$(gmt math -Q 3 PI MUL =)
	vecste=$(gmt math -Q 1 32 DIV =)

        # x
	gmt math -T$vecsta/$vecsto/$vecste T -o0 = x.txt
       # y = sin(x)
	gmt math -Q x.txt SIN = y.txt 
        #y2 = A cos(x+B)
	gmt math -Q x.txt PI 3 DIV ADD COS 4 PI MUL 10 DIV MUL = y2.txt

        # Shading for red<blue
	gmt math -Q y.txt y2.txt LE 0 NAN y.txt MUL = y_c.txt
        # Shading for red>blue
	gmt math -Q y.txt y2.txt GE 0 NAN y2.txt MUL = y2_c.txt

        # All in one file (for -Sb+base option)
	paste x.txt y.txt y2.txt y_c.txt y2_c.txt > file.txt

        # Graph-paper
	gmt basemap -R-10/10/-2/2 -JX10c -Bxafpigpi -Byafg -BWS+t"Relative anomaly" --MAP_FRAME_TYPE=graph-origin+o0/0 --MAP_GRID_PEN=lightgray
 
        # Plot sines
	gmt plot file.txt -i0,1 -Wthick,blue -l"@[\sin(x)@["
	gmt plot file.txt -i0,2 -Wthick,red -l"@[\frac{4\pi}{10}\cos(x+\frac{\pi}{3})@["

        # Plot shades
	gmt plot file.txt -i0,3,2 -Gred@90 -Sb${vecste}q+b -l"red > blue"
	gmt plot file.txt -i0,4,1 -Gblue@90 -Sb${vecste}q+b -l"red < blue"

gmt end show

@PaulWessel

Copy link
Copy Markdown
Contributor Author

Not merged - this is WIP branch only. - need to build that branch.

@gd-a

gd-a commented Jun 25, 2022

Copy link
Copy Markdown
Contributor

need to build that branch

I'm a simple man.

@PaulWessel

Copy link
Copy Markdown
Contributor Author

Your example looks like this:

test

@PaulWessel

Copy link
Copy Markdown
Contributor Author

Which tells me that if only one axis is selected we do not have to block the labeling of the origin since there is no overprint.

@gd-a

gd-a commented Jun 25, 2022

Copy link
Copy Markdown
Contributor

if only one axis is selected

Indeed. Do you throw an error if Joker asks for -BWSEN or similar ?

@PaulWessel

Copy link
Copy Markdown
Contributor Author

Not yet, but silently ignore anything but WwlSsb

@PaulWessel

PaulWessel commented Jun 26, 2022 •

Copy link
Copy Markdown
Contributor Author

Still need to update the example plot in gmt.conf of the various basemaps to include the graph-origin. @gd-a example with both axis looks like this:

test

I am unsure if we should automatically add to the title offset (the length of the extension) or if the user should use --MAP_TITLE_OFFSET.

@gd-a

gd-a commented Jun 26, 2022

Copy link
Copy Markdown
Contributor

silently ignore anything but WwlSsb

The secret to peace of mind.

It looks neat ! (Well, except for the ugly plot lines)
I'd add the offset, else users would have to declare it every time, which have a tendency to clutter the code.

@PaulWessel

Copy link
Copy Markdown
Contributor Author

Now with auto shift:
test

@PaulWessel PaulWessel changed the title WIP Allow MAP_FRAME_TYPE=graph-centered Allow MAP_FRAME_TYPE=graph-origin Jun 27, 2022
@PaulWessel

Copy link
Copy Markdown
Contributor Author

Documentation and code has been updated to use graph-origin and the figure and script in gmt.conf has been expanded to include the graph-origin basemap. I think this PR is now ready for final review:

GMT_map_frame_type

@joa-quim

Copy link
Copy Markdown
Member

Agree that graph-origin is better (a little shorter).

Another thing. Your example figure shows that the figures are small the fonts are still too big.

@PaulWessel

Copy link
Copy Markdown
Contributor Author

Agree the fonts are too big here. Maybe it is a subplot thing? Anyway, separate issue from graph-origin.

@joa-quim joa-quim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Blind aproval.

@PaulWessel

Copy link
Copy Markdown
Contributor Author

Given Joaquim's blind approval, it would be good if @seisman @Esteban82 and @meghanrjones give it a try first before I merge.

@PaulWessel PaulWessel added documentation Improve documentation enhancement Improving an existing feature and removed discussion Topics for longer discussion labels Jun 28, 2022
Comment thread src/gmt_defaults.h Resolved
@seisman

seisman commented Jun 28, 2022

Copy link
Copy Markdown
Member

Do you think it makes more sense to have the default origin at the center of the x- and y-range. For example, for -R10/30/-20/-10, the default origin is +o20/-15.

gmt basemap -JX5c -R10/30/-20/-10 -Baf -BWS --MAP_FRAME_TYPE=graph-origin -png map

map

Comment thread src/gmt_plot.c Resolved
@seisman

seisman commented Jun 28, 2022

Copy link
Copy Markdown
Member

-Blb and -Bls don't work as expected:

gmt basemap -Baf -Blb -JX5c -R-10/10/-10/10 --MAP_FRAME_TYPE=graph-origin -png map
gmt basemap -Baf -BlS -JX5c -R-10/10/-10/10 --MAP_FRAME_TYPE=graph-origin -png map

PaulWessel and others added 2 commits June 28, 2022 10:35
Co-authored-by: Dongdong Tian <[email protected]>
Co-authored-by: Dongdong Tian <[email protected]>
@PaulWessel

Copy link
Copy Markdown
Contributor Author

Do you think it makes more sense to have the default origin at the center of the x- and y-range. For example, for -R10/30/-20/-10, the default origin is +o20/-15

No, I think that would be a problem. Lets say I use -R-10/20/-20/10. I would want the axes at the origin, but your default would place them at (5,-5) which is useless. So now I would have to add +o0/0 to make sure every time. I think it is better the other way, that you should have to do +o20/-15 instead.

Perhaps a getter solution would be an optional +oc for "Center the axes on the given domain", with the default still being the origin at (0,0)?

@seisman

seisman commented Jun 28, 2022

Copy link
Copy Markdown
Member

Do you think it makes more sense to have the default origin at the center of the x- and y-range. For example, for -R10/30/-20/-10, the default origin is +o20/-15

No, I think that would be a problem. Lets say I use -R-10/20/-20/10. I would want the axes at the origin, but your default would place them at (5,-5) which is useless. So now I would have to add +o0/0 to make sure every time. I think it is better the other way, that you should have to do +o20/-15 instead.

Perhaps a getter solution would be an optional +oc for "Center the axes on the given domain", with the default still being the origin at (0,0)?

Sounds good to me.

@PaulWessel

Copy link
Copy Markdown
Contributor Author

Please check again, @seisman. The +oc has been implemented and I fixed the lack of reset for unannotated axes.

@PaulWessel
PaulWessel merged commit 0cef866 into master Jul 2, 2022
@PaulWessel
PaulWessel deleted the centered-graph-axes branch July 2, 2022 15:36
@maxrjones maxrjones added the add-changelog Add PR to the changelog label Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add-changelog Add PR to the changelog documentation Improve documentation enhancement Improving an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants