GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
758 stars 220 forks source link

[Easy task if you know some sphinx] Add example for setting map title #335

Closed weiji14 closed 3 years ago

weiji14 commented 5 years ago

Description of the problem

Even though it's in the title, our map :world_map: tutorial for setting map frames, ticks, titles and labels doesn't actually teach us how to set a title!

Current title-less map

We'll need your help :wave: to add that to the example. You'll be working on the pygmt/examples/tutorial/frames.py file which you can edit here or in your Text Editor or Integrated Development Environment (IDE).

To do that, you'll need to know how to use the the frame (B) setting in the basemap function. Specifically, you might need to refer to the GMT docs on setting the B-option. This one line of code below (adapted from https://github.com/GenericMappingTools/pygmt/pull/325#issuecomment-540203439) is part of what you need to do the trick:

fig.basemap(frame=["ag", "+tTitle"]

You can find out more about contributing in our CONTRIBUTING.md docs. Leave a comment below if you'd like to start working on this and feel free to ask for help! It's actually as much of a learning experience for us as it will be for you :smile:

Stretch goals

In addition to setting a title, Find out how to set an x-axis label called "Longitude" and y-axis label called "Latitude"!

weiji14 commented 4 years ago

@Jessie42 will be working on this!

weiji14 commented 4 years ago

https://www.gitpod.io/#/https://github.com/GenericMappingTools/pygmt

kmaterna commented 4 years ago

I noticed the same thing. Putting title-setting in the docs would be super helpful. It's slightly tricky with escape-character-quotations... Not sure if you want to explain things like this in the tutorials, but you can set the title on the fly like this:

# my_variable is a string (ex: "shear stress")
title="+t\"Map of "+my_variable+" values\"";
fig.basemap(frame=["ag", title];
willschlitzer commented 3 years ago

I'll take on this issue.

willschlitzer commented 3 years ago

@weiji14 I'm struggling with the stretch goals of adding the axis labels. I thought it would be the same as setting the labels on the color bars, and the arguments would be x+lLongitude and y+lLatitude but that is not plotting any axis labels. I can't find anything in the PyGMT or GMT docs for the solution; any idea?

seisman commented 3 years ago

the arguments would be x+lLongitude and y+lLatitude but that is not plotting any axis labels

GMT doesn't allow adding labels to geographic maps. As for geographic maps, the X-axis is always longitude and the Y axis is always latitude.

willschlitzer commented 3 years ago

Since the rest of the tutorial is for geographic maps, do you think it's better to use a non-geographic map for this last part or just not include axis labels in this tutorial?

seisman commented 3 years ago

I don't have a good idea for this. Perhaps it's better to show labels for non-geographic maps and also explain why it doesn't work for geographic maps.

willschlitzer commented 3 years ago

That's a good idea; I'll add it tomorrow

willschlitzer commented 3 years ago

Currently struggling with adding the labels. I'm using: fig.basemap(region=[0, 10, 0, 20], projection="X4i/3i", frame=["x+lx-axis", "y+ly-axis"])

It is plotting the x-axis label on both the top and bottom and the y-axis label on the left and right side. Not seeing anything in the GMT docs to specify that it only print in one location; any ideas?

weiji14 commented 3 years ago

Try with frame=["WSne", "x+lx-axis", "y+ly-axis"].

willschlitzer commented 3 years ago

It worked! Thanks

willschlitzer commented 3 years ago

@weiji14 @seisman Would needing to add the "WSne" argument be best explained that, by default, all axes are designated as primary axes and "WSne" is needed to make only the left and bottom axes primary?

seisman commented 3 years ago

Closed by #720.