-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for "makecpt" style colormap functionality in grdimage and colobar #372
Comments
It's not very well documented, but we do have a makecpt function as of #329. It actually works via The way you would do this in your code snippet then is as follows: pygmt.makecpt(series=[min, max], cmap=...)
fig.grdimage(...)
fig.colorbar(...) |
After playing around with
|
I agree that Point 1: . Right now if you want to change to another colormap, you'll need to call fig = pygmt.Figure()
pygmt.makecpt(cmap="geo")
fig.grdimage(,,,)
fig.show()
fig = pygmt.Figure()
pygmt.makecpt(cmap="oleron")
fig.grdimage(,,,)
fig.show() rather than this: pygmt.makecpt(cmap="geo")
fig = pygmt.Figure()
fig.grdimage(,,,)
fig.show()
pygmt.makecpt(cmap="oleron")
fig = pygmt.Figure()
fig.grdimage(,,,)
fig.show() The first one creates a cpt specifically for the figure, whereas the second one creates a session colormap as you said that can't be overridden. Point 2. This would definitely be a better way. and what you're asking for here I think is similar to what was tried in #126. |
Here is my suggestion on how to resolve this problem:
|
I have not yet tried the new modern mode in GMT 6, but I read the note that @weiji14 linked. It seems that GMT 6 uses "hidden" files to store potentially several colormaps with a hierarchy of scope for different parts of the figure. I understand that PyGMT is keeping things simple, so supporting a hierarchy of colormaps with different scope might be too much. It still seems like it is very confusing to not be able to change the session colormap for each figure, as Mark found. I often plot several datasets in a single figure with different colormaps for each one, and it sounds like the present implementation of PyGMT would make that impossible. I am not clear whether creating a new figure object clears what was plotted before or overlays it in PyGMT. If I were to try to do the plots that I do with mulitple colormaps in one figure, it would be something like this:
|
I'm so confused about the discussions above. Could you give some examples which don't work as expected? To me, the following script works as expected: import pygmt
fig = pygmt.Figure()
pygmt.makecpt(cmap="etopo1")
fig.grdimage("@earth_relief_10m", projection="H10c", frame=True)
fig.colorbar(frame=True)
fig.shift_origin(yshift="10c")
pygmt.makecpt(cmap="earth")
fig.grdimage("@earth_relief_10m", projection="H10c", frame=True)
fig.colorbar(frame=True)
fig.savefig("map.pdf") |
try this!
Both images look exactly the same. Edit: Also the "Y" option is undocumented. It is good to know that this exists. |
@MarkWieczorek Yes, your example doesn't work as expected to me. I believe it's an upstream (i.e. the core GMT) bug, and I've opened an issue in GenericMappingTools/gmt#2006. For your example, the current working solution is to put the As for the "Y" option, it's equivalent to the |
Hi I can not figure out like how to use custom colors for cmap in place of using the color master color palette? Is this possible? If yes then how one does that? I see that in gmt one can do that but how to do this in pygmt? |
Do you mean using a custom CPT file or custom colors? If you already have a custom CPT file in your current directory, you should be able to use it like Or if you want to define a CPT from a series of colors, BTW, it would be better if you can ask further questions in the GMT Forum. |
Thanks very much. It worked. It was the second one cmap="red,blue,yellow". |
In classic gmt the function
makecpt
is used to create a "cpt" file that acts as a color map for plotting data ingrdimage
and in plotting a colorbar.In its present state, pygmt does not (to the best of my knowledge) allow for creating a custom colormap for use in both
grdimage
andcolorbar
, which greatly limits the utility of pygmt. Such functionality could be achieved in the following way:In practice, a single image could have several cpt files associated with it.
The text was updated successfully, but these errors were encountered: