Closed firstkingofrome closed 4 years ago
Hi @firstkingofrome,
Thanks for using PyGMT, and taking the time to writeup such a detailed issue! So the trick here is not to set the transparency in the makecpt
command, but in the grdimage
using the -t
transp option.
fig = pygmt.Figure()
fig.basemap(region=region, projection="M8i", frame=True)
# plot the underlying xarray (in my real problem this would be my hillshade)
fig.grdimage(underlayedXarray, C="gray")
# Now create a cpt file with the transparency option to plot over the last grdimage
pygmt.makecpt(cmap="viridis", series=[0.0, np.max(sampleXarray.data)], continuous=True)
fig.grdimage(sampleXarray, C=True, t=60)
fig.savefig("test.png")
fig.show()
You'll notice that it's possible to use pygmt.makecpt
as of #329 (see also #372 as to why it's pygmt.makecpt
and not fig.makecpt
). Anyways, the code above should produce:
If this answers your question, feel free to close this issue.
Hello @weiji14 thank you for you're help! That solves my problem perfectly, also thanks for letting me know about the pygmt.makecpt support.
The 'transparency' (-t) long alias was added in #614, and should be available in the next PyGMT v0.2.1 release :wink:.
Hello, I am trying to plot a grdimage over a hillside (another grid image). I normally would do this by using a color map with a transparency setting for the last grdimage (so that the hillside is visible underneath). It appears that the transparency instructions in my grdimage command are being ignored. I tried using a number of different outputs from the fig.savefig (pdf, png) with the same result. Thank You, any help is greatly appreciated!
The code below shows the issue (generates 2 fake xarrays and a color map with the specified transparency, plotting them over each other shows that the transparency instructions are ignored), you can just paste it into a blank jupyternotebook or ipython shell and it will run (it generates some fake data, and then attempts to plot one over the other using a transparent color map)