-
Notifications
You must be signed in to change notification settings - Fork 229
Dynamic legend labels with space in it #1632
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
Comments
👋 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. |
Hi @thomas-romuald, this is a problem related to #247, there are two possible workarounds.
import pygmt
# Legend labels
label_restricted= "Data requering owner`s authorization "+str(10//3)+" points"
label_open = "Available data "+str(20//3)+" points"
print(label_restricted)
print(label_open)
# Create map with shorelines and borders
fig = pygmt.Figure()
fig.basemap(region=[12, 56, 34, 78], frame="ag", projection="M25c")
fig.coast(shorelines="1/0.5p,black", borders="1/0.5p,black")
# Plot data
# if data_restricted.empty == False:
fig.plot(x=12, y=34, style="t0.08c", color="red", pen="red", label=f'"{label_restricted}"+S0.50c')
# if data_open.empty == False:
fig.plot(x=56, y=78, style="t0.08c", color="blue", pen="blue", label=f'"{label_open}"+S0.50c')
# Add legend outside the map frame
fig.legend(position="JMB+o1.4c", box=True)
fig.show() produces: Let us know if this works for you, or if you have any other questions on usage. We'll try to get this 'space in string' bug fixed in the next version, since it's been an ongoing problem for a while. I'll remind myself to add your failing example as a test in the bugfix at #1487. |
Hi @weiji14 thank you very much for your support ! It works now! |
Cool, great to hear! The team has done an amazing job over the years, and it's always great to see more people using it 😀. If you have any other questions, feel free to ask them on the GMT forum at https://forum.generic-mapping-tools.org (you can use your GitHub login to sign in). I'll keep this bug report open for a while until #1487 is merged. |
Description of the problem
I would like to display the number of dots in the legend. This number is not static it comes from a data file.
However, I don't understand how to do it with space in the text. The
label='"this is my data"'
works only for static data.May I help on this ?
Full code that generated the error
Works
Does not work
Rest of the code
Full error message
System information
Please paste the output of
python -c "import pygmt; pygmt.show_versions()"
:The text was updated successfully, but these errors were encountered: