Closed lonnylundsten closed 3 years ago
👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.
Not elegant, but I was able to solve this problem by creating an auto-coded color column from my categorical column (conceptname):
#convert conceptname to cetegory and add auto-coded color column
df.conceptname = pandas.Categorical(df.conceptname)
df['colors'] = df.conceptname.cat.codes
Then I was able to use the color column for colors and a standard gmt cmap for my colormap:
#plot df lat/lon points on map
fig.plot(x=df.longitude, y=df.latitude, color=df.colors.astype('int64', copy=False), cmap='rainbow',style='c0.2c',pen='black')
The bolded bits in this code plot the scale bar (L flag) and directional rose (Td flag).
#set gmt region, projection, and map view
fig.coast(region=df_region,projection='M-120/42/14', frame=True,land='darkgrey', water='lightgrey', shorelines=0,borders='a',**L='g-128/23.8+c-120/40+w500k', Td='g-130/26+w2c'**)
This info is listed in the API reference: https://www.gmtpython.xyz/latest/api/index.html
Note that each heading in the API reference is hyperlinked to further info, ie: https://www.gmtpython.xyz/latest/api/generated/gmt.Figure.basemap.html#gmt.Figure.basemap
And then that link will direct you to the official GMT docs for even more info. http://gmt.soest.hawaii.edu/doc/latest/basemap.html
@lonnylundsten sorry for the delay. Were you able to plot it in the end?
Do you want the colors to be taken from a colormap or just use different colors? If you just want some different colors, this is something that doesn't work well in GMT. I think you need to do it manually currently. There is some talk of implementing this in the base GMT but it might take a while. We could probably implement this on the Python side in the mean time. I'll have to think of a good way to do it.
Yes, I was able to implement this using the code above. I created my own color map, which worked great. Thanks!
Oops. I did not mean to close this. I'm at sea and the internet is being laggy! Now reopened. LL
To close this >2 year old issue, I think it would be great if someone can add an example to our gallery that demonstrates how to "Color points by categories". The 3D Scatter Plot example actually covers this, but it would be nice to have a simpler, 2D example.
One way would be to just copy and modify https://www.pygmt.org/v0.3.0/gallery/plot/scatter.html, and instead of using a for-loop, use fig.plot(..., color=df.color_column.cat.codes.astype(int), ...)
instead. Let us know (anyone) if you're interested in helping, have a look at CONTRIBUTING.md, and we'll be happy to guide you through!
Hello, Thanks for GMT/Python! I am making maps by querying our database for various species and adding points to a basemap -- see attached. I followed the instructions for plotting earthquake magnitude and color coding but that seems to fail with categorical data such as species names. In the attached figure I have a species column in my df with multiple species and I would like to have them plotted as different colored circles on the map. Matplotlib/seaborn etc., allow you to set 'Hue=df.category' for this type of data. Perhaps this could be implemented in gmt-python?