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

Improve the colorbar example #595

Closed seisman closed 4 years ago

seisman commented 4 years ago

Description of the problem

We already have an example for colorbar in the gallery (https://www.pygmt.org/dev/gallery/plot/colorbar.html). However, the example is a little low-quality.

  1. The example gives many warnings like:

    colorbar [WARNING]: Axis sub-item f set more than once (typo?)
    colorbar [WARNING]: Axis sub-item a set more than once (typo?)
  2. The example is not beautiful at all. The main reason is that the figure size is too small and the colorbars are too large.

  3. The example is not as usable as I expect. I believe very few people will plot colorbars inside a frame. IMHO, at least we should show

    1. calling colorbar with very few arguments, using the default location and default size
    2. the easiest way (using J) to plot colorbars outside the basemap.

@weiji14 As the example was created by you, I'd like to hear what you think. You can improve the example if you like.

weiji14 commented 4 years ago

Oo, those warnings definitely aren't nice to have, and yes, the example could definitely look a bit nicer, I got carried away with the different positioning methods at #373

  1. calling colorbar with very few arguments, using the default location and default size

From memory, I don't think there's a default position and/or box (unlike legend which does). Will probably need to wrap in a few more long aliases to fig.colorbar to make this easier.

  1. the easiest way (using J) to plot colorbars outside the basemap.

Yes, this would be good to show.

Maybe we could reproduce (a subset) of the colorbars plotted at https://docs.generic-mapping-tools.org/latest/cookbook/cpts.html?

seisman commented 4 years ago

From memory, I don't think there's a default position and/or box (unlike legend which does). Will probably need to wrap in a few more long aliases to fig.colorbar to make this easier.

There are defaults. Try this example:

import pygmt

fig = pygmt.Figure()
fig.basemap(region="0/10/0/10", projection="X10c/10c", frame=True)
fig.colorbar(cmap="vik", frame=True)
fig.savefig("map.pdf")

However, I still don't like this one, because usually, what we do is calling makecpt to create a "current" cpt, plot some thing, and then calling colorbar without using cmap.

weiji14 commented 4 years ago

From memory, I don't think there's a default position and/or box (unlike legend which does). Will probably need to wrap in a few more long aliases to fig.colorbar to make this easier.

There are defaults. Try this example:

import pygmt

fig = pygmt.Figure()
fig.basemap(region="0/10/0/10", projection="X10c/10c", frame=True)
fig.colorbar(cmap="vik", frame=True)
fig.savefig("map.pdf")

However, I still don't like this one, because usually, what we do is calling makecpt to create a "current" cpt, plot some thing, and then calling colorbar without using cmap.

Ah ok, then we should definitely show that this default position/style exists. I've opened a PR at #596, feel free to experiment on that branch or offer suggestions.