Skip to content

Conversation

@PaulWessel
Copy link
Member

Description of proposed changes

See issue #5182 for background. This PR lets a negative MAP_LABEL_OFFSET be interpreted as the absolute distance from the axis to the base of the label [The default is that a positive offset is seen as a relative addition beyond the end of the annotations]. The use for this is to better align multiple y-axes plots that are stacked so that the labels align even if the annotations have different magnitudes and formats. TO demonstrate this effect I added a test based on the original poster's issue. This plot is found below this text. One remaining issue is whether of not we restrict this mechanism to just the y-axis. There are two different consequences depending on the answer:

  • If applicable to all axis then the user may need to use separate basemap calls so that the effect only applies to the label they want.
  • If only applicable to the y-axis then one cannot align x-labels on stacks of plots in several columns, and not just this example of one column.

For these reasons I favor not imposing any restriction on which axis it applies to. Also note: The offset is the exact absolute distance between axis and base of label . That means it is the same on both left and right axis, but since the base is on the right there is a difference. Another question is then if we need to ensure it works symmetrically on left and right, meaning on the right axis (and bottom) we must deal with the absolute distance to the top of the label.

Comments please.

fixed_labeldist

@PaulWessel PaulWessel added new feature PR that implements a new feature or capability in GMT new core module feature PR that implements a new core module feature labels Jun 10, 2021
@PaulWessel PaulWessel added this to the Future release milestone Jun 10, 2021
@PaulWessel PaulWessel self-assigned this Jun 10, 2021
@seisman
Copy link
Member

seisman commented Jun 10, 2021

This PR lets a negative MAP_LABEL_OFFSET be interpreted as the absolute distance from the axis to the base of the label

It's backward-incompatible, right?

@PaulWessel
Copy link
Member Author

Do you mean we already are using a negative label offset for something else?

@seisman
Copy link
Member

seisman commented Jun 10, 2021

Do you mean we already are using a negative label offset for something else?

People may be using a negative label offset to make labels closer to the axis.

@PaulWessel
Copy link
Member Author

OK, I can imagine people doing that. The alternative implementation would then be some sort of flag to interpret the offset the absolute way. MAP_LABEL_OFFSET=offset[unit][+a] with a modifier for absolute. Not sure if this is the first defaults setting with a modifier so perhaps that is a bad precedent. The final alternative is a separate and new defaults setting like MAP_LABEL_MODE=auto|absolute [auto].

And I guess it really should measure from the axis outward to the start of the label, be it to the base of the top of it, so that means working this into PostScript for exact height, etc.

@maxrjones
Copy link
Member

OK, I can imagine people doing that. The alternative implementation would then be some sort of flag to interpret the offset the absolute way. MAP_LABEL_OFFSET=offset[unit][+a] with a modifier for absolute. Not sure if this is the first defaults setting with a modifier so perhaps that is a bad precedent. The final alternative is a separate and new defaults setting like MAP_LABEL_MODE=auto|absolute [auto].

And I guess it really should measure from the axis outward to the start of the label, be it to the base of the top of it, so that means working this into PostScript for exact height, etc.

Is it possible to make these both customizable for x and y axes independently? For example, --MAP_LABEL_OFFSET 12p/24p --MAP_LABEL_MODE annot/axis for 12p x-axis labels relative to the annotations and 24p y-axis labels relative to the axis.

Either way, I prefer MAP_LABEL_MODE to +a, but find annot/axis more descriptive than auto/absolute.

@maxrjones maxrjones added the add-changelog Add PR to the changelog label Jun 12, 2021
@PaulWessel
Copy link
Member Author

I have introduced the new GMT defaults MAP_LABEL_MODE = annot|axis which can be set separately for the x and y axis via a slash. Similarly, the MAP_LABEL_OFFSET can now be given separate offsets for x and y if desired. With these upgrades we can offer support for having proper alignment of numerous y-axis labels without imposing the same condition on the x-axis. But we could, if we wish to align several sets of x labels across columns.
All tests still pass.

@maxrjones
Copy link
Member

Do you think it is possible to update the auto settings for MAP_LABEL_OFFSET to work better when MAP_LABEL_MODE is set to axis?

gmt begin panels pdf
  gmt subplot begin 2x1 -Fs8c -M20p -A -SCb -SRl
    gmt set MAP_LABEL_MODE axis/axis MAP_LABEL_OFFSET auto/auto
    gmt subplot set
    gmt basemap -R0/8000/0/1000 -BWSne -Bya+l"Axis label"
    gmt subplot set
    gmt basemap -R0/80/0/10 -BWSne -Bya+l"Axis label"
  gmt subplot end
gmt end show

panels

@PaulWessel
Copy link
Member Author

We could, but no single value will work well I think. But I agree 8p is not it! Suggestions?

@maxrjones
Copy link
Member

We could, but no single value will work well I think. But I agree 8p is not it! Suggestions?

32p seems OK. Maybe it would be worth adding a warning as well for MAP_LABEL_OFFSET=auto with MAP_LABEL_MODE=axis, like what is done if annotations are removed due to gmt.conf settings.

@PaulWessel
Copy link
Member Author

Yes, that would be good. So 8p/32p for the two types of offsets plus warning for axis actions. Would you like to try this?
-p

@maxrjones
Copy link
Member

Yes, that would be good. So 8p/32p for the two types of offsets plus warning for axis actions. Would you like to try this?
-p

Do you mean implementing the changes or testing? Fine doing either.

@PaulWessel
Copy link
Member Author

Sorry, meant implementing etc. Includes doc update I think as well.

@maxrjones
Copy link
Member

Sorry, meant implementing etc. Includes doc update I think as well.

Yes, will do.

Co-authored-by: Meghan Jones <meghanj@alum.mit.edu>
PaulWessel and others added 2 commits June 15, 2021 14:50
Co-authored-by: Meghan Jones <meghanj@alum.mit.edu>
Co-authored-by: Meghan Jones <meghanj@alum.mit.edu>
@PaulWessel
Copy link
Member Author

Sorry, I completely forgot to access these suggestions...

@maxrjones
Copy link
Member

OK, I seem to be having the subplot related problem again. Is something wrong in the second example here?
Example 1 (works as expected, with MAP_LABEL_OFFSET = 32p)

gmt begin panels pdf
  gmt set MAP_LABEL_MODE axis
  gmt subplot begin 2x2 -Fs8c -M25p
    gmt subplot set
    gmt basemap -By+ltest -Bx+ltest -R0/8000/0/1000
    gmt subplot set
    gmt basemap -By+ltest -Bx+ltest -R0/8000/0/1000
    gmt subplot set
    gmt basemap -By+ltest -Bx+ltest -R0/80/0/10
    gmt subplot set
    gmt basemap -By+ltest -Bx+ltest -R0/80/0/10
  gmt subplot end
gmt end show

panels
Example 2 (MAP_LABEL_OFFSET still uses auto scaling):

gmt begin panels png
  gmt subplot begin 2x2 -Fs8c -M25p
    gmt set MAP_LABEL_MODE axis
    gmt subplot set
    gmt basemap -By+ltest -Bx+ltest -R0/8000/0/1000
    gmt subplot set
    gmt basemap -By+ltest -Bx+ltest -R0/8000/0/1000
    gmt subplot set
    gmt basemap -By+ltest -Bx+ltest -R0/80/0/10
    gmt subplot set
    gmt basemap -By+ltest -Bx+ltest -R0/80/0/10
  gmt subplot end
gmt end show

panels

@PaulWessel
Copy link
Member Author

I get the same, so looks like 6p is scaled to ~the same. It is clearly not scaling 32p to something. Not obvious anything in the code is wrong. May need to debug.
Oh, the issue is that you are setting the MAP_LABEL_MODE too late. subplot has already done the calculations and made a gmt.conf for the subplot based on the 6p then the mode changes...

GMT->current.setting.map_label_offset = 6 * pt * scale; /* 6p */
if (gmt_M_is_dnan (GMT->current.setting.map_label_offset[GMT_X])) {
if (GMT->current.setting.map_label_mode[GMT_X] == GMT_LABEL_AXIS)
GMT->current.setting.map_label_offset[GMT_X] = 32 * pt;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
GMT->current.setting.map_label_offset[GMT_X] = 32 * pt;
GMT->current.setting.map_label_offset[GMT_X] = 32 * pt * scale;

I set this as constant intentionally, but in retrospect scaled might be better.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you still want this suggestion to be active?

@maxrjones
Copy link
Member

I get the same, so looks like 6p is scaled to ~the same. It is clearly not scaling 32p to something. Not obvious anything in the code is wrong. May need to debug.
Oh, the issue is that you are setting the MAP_LABEL_MODE too late. subplot has already done the calculations and made a gmt.conf for the subplot based on the 6p then the mode changes...

OK, so it should not be expected to work. Thanks for the explanation.

@PaulWessel PaulWessel changed the title WIP Allow for a fixed label offset Allow for a fixed label offset Jun 16, 2021
@PaulWessel PaulWessel merged commit 67471c1 into master Jun 16, 2021
@PaulWessel PaulWessel deleted the fixed-label-offset branch June 16, 2021 02:40
@seisman seisman removed this from the Future release milestone Jan 7, 2024
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 new core module feature PR that implements a new core module feature new feature PR that implements a new feature or capability in GMT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants