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

Allow non-string color when input data is a matrix or a file for plot and plot3d #1526

Merged
merged 4 commits into from
Oct 7, 2021

Conversation

seisman
Copy link
Member

@seisman seisman commented Sep 19, 2021

Description of proposed changes

The following script raises an error with PyGMT v0.4.1 and the master branch:

import pygmt
fig = pygmt.Figure()
fig.plot(data=[[3, 3], [5, 5]], frame=True, region=[0, 10, 0, 10], style="c1c", color=200)
fig.show()

because the following code is too strict about the color type.

pygmt/pygmt/src/plot.py

Lines 242 to 248 in f7d5526

if "G" in kwargs and not isinstance(kwargs["G"], str):
if kind != "vectors":
raise GMTInvalidInput(
"Can't use arrays for color if data is matrix or file."
)
extra_arrays.append(kwargs["G"])
del kwargs["G"]

This PR fixed the check to make sure that types like string, float, boolean or None can be used.

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@seisman seisman added this to the 0.5.0 milestone Sep 19, 2021
@seisman seisman marked this pull request as draft September 19, 2021 06:58
@seisman seisman changed the title Allow non-string color when input data is a matrix or a file for plot and plot3d WIP: Allow non-string color when input data is a matrix or a file for plot and plot3d Sep 19, 2021
@seisman seisman changed the title WIP: Allow non-string color when input data is a matrix or a file for plot and plot3d Allow non-string color when input data is a matrix or a file for plot and plot3d Sep 19, 2021
@seisman seisman added the bug Something isn't working label Oct 4, 2021
@seisman seisman marked this pull request as ready for review October 4, 2021 09:49
@@ -302,12 +302,13 @@ def test_plot_sizes_colors_transparencies():
return fig


@pytest.mark.mpl_image_compare
@pytest.mark.mpl_image_compare(filename="test_plot_matrix.png")
@pytest.mark.parametrize("color", ["#aaaaaa", 170])
Copy link
Member

@weiji14 weiji14 Oct 5, 2021

Choose a reason for hiding this comment

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

Should we set G="sequence" so that people can input RGB or CMYK colors as a list like [170, 170, 170] or [0, 0, 0, 33] which gets converted to 170/170/170 and 0/0/0/33 respectively? Ref https://docs.generic-mapping-tools.org/6.2/gmtcolors.html#description.

Edit: Oh wait, this will be messy since color can be a 1d array... Maybe not.

@weiji14 weiji14 added the final review call This PR requires final review and approval from a second reviewer label Oct 5, 2021
@willschlitzer willschlitzer mentioned this pull request Oct 7, 2021
35 tasks
@seisman seisman merged commit 0d07ccc into main Oct 7, 2021
@seisman seisman deleted the fix-plot-G branch October 7, 2021 23:28
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Mar 18, 2022
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
… and plot3d (GenericMappingTools#1526)

* Allow non-string color when input data is a matrix or a file for plot and plot3d

* Expand existing tests to test int type colors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants