Skip to content
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

Figure.legend: Support passing a StringIO object as the legend specification #3438

Merged
merged 43 commits into from
Sep 19, 2024

Conversation

seisman
Copy link
Member

@seisman seisman commented Sep 12, 2024

Description of proposed changes

This PR adds StringIO support to Figure.legend, so that we can pass a StringIO object containing the legend specification to Figure.legend.

Need to wait for #3326.

Closes #571 and #576.

Example

import io
import pygmt

spec = io.StringIO(
"""
G -0.1i
H 24p,Times-Roman My Map Legend
D 0.2i 1p
N 2
V 0 1p
S 0.1i c 0.15i p300/12 0.25p 0.3i This circle is hachured
S 0.1i e 0.15i yellow 0.25p 0.3i This ellipse is yellow
S 0.1i w 0.15i green 0.25p 0.3i This wedge is green
S 0.1i f 0.25i blue 0.25p 0.3i This is a fault
S 0.1i - 0.15i - 0.25p,- 0.3i A contour
S 0.1i v 0.25i magenta 0.5p 0.3i This is a vector
S 0.1i i 0.15i cyan 0.25p 0.3i This triangle is boring
D 0.2i 1p
V 0 1p
N 1
M 5 5 600+u+f
G 0.05i
I @SOEST_block4.png 3i CT
G 0.05i
G 0.05i
L 9p,Times-Roman R Smith et al., @%5%J. Geophys. Res., 99@%%, 2000
G 0.1i
T Let us just try some simple text that can go on a few lines.
T There is no easy way to predetermine how many lines may be required
T so we may have to adjust the height to get the right size box.
""")

fig = pygmt.Figure()
fig.legend(spec, region=[0, 10, 0, 10], projection="M6i", position="x0.5i/0.5i+w5i+jBL+l1.2")
fig.show()

legend

@seisman seisman changed the title POC + WIP: Figure.legend: Support passing a StringIO object as the legend specification Figure.legend: Support passing a StringIO object as the legend specification Sep 13, 2024
@seisman seisman added the enhancement Improving an existing feature label Sep 13, 2024
@seisman seisman added this to the 0.14.0 milestone Sep 13, 2024
Base automatically changed from api/virtualfile-from-stringio to main September 18, 2024 23:42
@seisman seisman added the needs review This PR has higher priority and needs review. label Sep 18, 2024
@seisman seisman marked this pull request as ready for review September 18, 2024 23:43
Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Nice to close another >4 year old issue at #571!

@seisman seisman removed the needs review This PR has higher priority and needs review. label Sep 19, 2024
@seisman seisman merged commit 5196ae6 into main Sep 19, 2024
20 checks passed
@seisman seisman deleted the legend/stringio branch September 19, 2024 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow Figure.legend to read from StringIO
3 participants