pygmt
pygmt copied to clipboard
Allow passing in a list/array of angle/font/justify values to text
Description of the desired feature
Following up from https://github.com/GenericMappingTools/pygmt/pull/481#pullrequestreview-434464455, it would be desirable if users can:
- Pass in a list/array of angle/font/justify values to
text
(currently only a single angle/font/justify value is allowed, and applied to all texts) - Handle more flexible input formats, e.g., -F+a+j+f and -F+a+f+j (see also https://github.com/GenericMappingTools/pygmt/issues/479#issuecomment-647067718).
On the non-user facing side, it would be nice too if we can pass the x,y,text
input via a virtualfile as mentioned in https://github.com/GenericMappingTools/pygmt/pull/321#discussion_r334993927, instead of a temporary tab-delimited file. This will be a more efficient method of passing data around rather than relying on the pandas.to_csv
method. Will need to modify virtualfile_from_vectors
to accept str
type arrays, see https://github.com/GenericMappingTools/pygmt/pull/481#discussion_r443133421.
Are you willing to help implement and maintain this feature? Happy to review a PR for it :smile:
Here are some technical notes, which may be useful (or may be wrong) if someone wants to implement this feature.
-
put_vector()
function (wrapper of GMT APIGMT_Put_Vector()
) can only pass numerical and datetime vectors/arrays to GMT API - All trailing strings should be passed to GMT API by the
GMT_Put_Strings()
function (no wrapper for it yet) - You can call
GMT_Put_Vectors()
multiple times, and pass one vector each time - You can only call
GMT_Put_Strings()
one time to pass one single string array to GMT
Thus, to implement this feature, you need to:
- wrap the
GMT_Put_Strings()
function, i.e.,put_strings()
- pass the leading numerical arrays to GMT via the
put_vector()
function one by one - Combine all the trailing arrays into one string array, and pass it to GMT via the
put_strings()
function - Keep your fingers crossed 🤞
For example, if you want to pass the following arrays to make text()
accept input format x, y, angle, justify, font, text:
x = [5.0, 6.0]
y = [6.0, 7.0]
angle = [30, 60]
justify = ['BL', 'TL']
font = ['16p,2,blue', '32p,3,red']
text = ["First label", "Second label"]
You need to:
- call
put_vectors()
three times, passing vectorsx
,y
,angle
, respectively - combine the three string arrays to a single one, e.g.,
new_string = ["BL 16p,2,blue First label", "TL 32p,3,red Second label"]
- pass the
new_string
to GMT by callingput_strings()
- Again, keep your fingers crossed 🤞
- Pass in a list/array of angle/font/justify values to
text
(currently only a single angle/font/justify value is allowed, and applied to all texts)
Will be addressed in PR https://github.com/GenericMappingTools/pygmt/pull/2720.
- Handle more flexible input formats, e.g., -F+a+j+f and -F+a+f+j (see also Parsing of additional arguments when plotting text from file #479 (comment)).
Not implemented yet, but better to track it in #479.
On the non-user facing side, it would be nice too if we can pass the
x,y,text
input via a virtualfile as mentioned in #321 (comment), instead of a temporary tab-delimited file. This will be a more efficient method of passing data around rather than relying on thepandas.to_csv
method. Will need to modifyvirtualfile_from_vectors
to acceptstr
type arrays, see #481 (comment).
Already done in https://github.com/GenericMappingTools/pygmt/pull/559.
In other words, this issue report will be closed by #2720.