pygmt icon indicating copy to clipboard operation
pygmt copied to clipboard

Allow passing in a list/array of angle/font/justify values to text

Open weiji14 opened this issue 4 years ago • 1 comments

Description of the desired feature

Following up from https://github.com/GenericMappingTools/pygmt/pull/481#pullrequestreview-434464455, it would be desirable if users can:

  1. 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)
  2. 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:

weiji14 avatar Jun 21 '20 02:06 weiji14

Here are some technical notes, which may be useful (or may be wrong) if someone wants to implement this feature.

  1. put_vector() function (wrapper of GMT API GMT_Put_Vector()) can only pass numerical and datetime vectors/arrays to GMT API
  2. All trailing strings should be passed to GMT API by the GMT_Put_Strings() function (no wrapper for it yet)
  3. You can call GMT_Put_Vectors() multiple times, and pass one vector each time
  4. 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:

  1. wrap the GMT_Put_Strings() function, i.e., put_strings()
  2. pass the leading numerical arrays to GMT via the put_vector() function one by one
  3. Combine all the trailing arrays into one string array, and pass it to GMT via the put_strings() function
  4. 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:

  1. call put_vectors() three times, passing vectors x, y, angle, respectively
  2. 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"]
  1. pass the new_string to GMT by calling put_strings()
  2. Again, keep your fingers crossed 🤞

seisman avatar Jun 22 '20 03:06 seisman

  1. 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.

  1. 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 the pandas.to_csv method. Will need to modify virtualfile_from_vectors to accept str 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.

seisman avatar Oct 07 '23 13:10 seisman