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 passing an array as symbols for plot #1117

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

core-man
Copy link
Member

@core-man core-man commented Mar 24, 2021

Description of proposed changes

We can only plot different symbols via the data parameter in the plot method. This PR allows passing an array as symbols via the new symbol parameter. Meanwhile, we have to set style="0.2c", or set 1d-array sizes using style=True and sizes=sizes. Therefore, we now have four ways to set symbols and sizes, e.g.,

  • constant symbol and size: style="c0.5c"
  • constant symbol and different sizes: style="cc" + sizes=sizes
  • different symbols and constant size: style="0.5c" + symbol=symbol
  • different symbols and sizes: style=True + sizes=sizes + symbol=symbol

Two tests are added:

  • test_plot_fail_1d_array_using_data: Raise GMTInvalidInput if symbol is used with data parameter. Actually, I rename test_plot_fail_color_size_intensity to be this test function since we should raise such an error for 1d-array color, size, intensity and symbol parameters if they are used with the data parameter. (originally posted in The transparency parameter of plot/plot3d methods can be 1d array #1098 (comment))
  • test_plot_symbols: test 1d-array symbol (all are "c") with style="0.5c".

Related #1076

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

@core-man core-man marked this pull request as draft March 24, 2021 10:06
@core-man
Copy link
Member Author

core-man commented Apr 13, 2021

1c48b39: If the symbol parameter is used, we will automatically set style to be True if it is not set by the user.

Therefore, now we can plot different symbols and sizes like this: symbol=symbol, sizes=sizes. Note that the sizes parameter only accepts int and float (e.g., 1, 0.5) and does not accept string (e.g., 0.5c), so the unit can have to be set by the PROJ_LENGTH_UNIT using the config method if we don't want to use the default cm. (Also posted in #1076 (comment))

@@ -206,15 +210,18 @@ def plot(self, x=None, y=None, data=None, sizes=None, direction=None, **kwargs):
kind = data_kind(data, x, y)

extra_arrays = []
if "S" in kwargs and kwargs["S"][0] in "vV" and direction is not None:
extra_arrays.extend(direction)
if "S" in kwargs and isinstance(kwargs["S"], str):
Copy link
Member Author

Choose a reason for hiding this comment

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

I added isinstance(kwargs["S"], str) in case that the style parameter is True, False, None, int, or float.

@core-man core-man marked this pull request as ready for review April 13, 2021 08:07
@core-man core-man mentioned this pull request Apr 13, 2021
5 tasks
@seisman
Copy link
Member

seisman commented Apr 14, 2021

@core-man I think the co-existence of style and symbol parameters will lead to more confusion. We should discuss what we would like to use about the plot() and plot3d() functions.

@core-man
Copy link
Member Author

core-man commented Apr 14, 2021

@core-man I think the co-existence of style and symbol parameters will lead to more confusion. We should discuss what we would like to use about the plot() and plot3d() functions.

Actually, I'd like to fully avoid using the style parameter, and use a more Pythonic way, e.g., sizes, symbol, direction. But now I don't know if how much work will have to be done before the style parameter is avoided since plot/plot3d still have many unimplemented and complicated features/options.

We could remove the style parameter now and directly use symbol instead (see your suggestion in #1072 (comment)? What do you think? This is also related to Backwards compatibility and deprecation policy (#1120).

@core-man core-man mentioned this pull request Apr 15, 2021
5 tasks
@seisman
Copy link
Member

seisman commented May 7, 2021

I believe we need more discussions about what we would like to see about the plot() function.
I'll convert this PR to draft.

@seisman seisman marked this pull request as draft May 7, 2021 04:52
projection="X4c",
color="blue",
sizes=np.full(len(data[:, 0]), 0.5),
symbol=np.full(len(data[:, 0]), "c"),
Copy link
Member

Choose a reason for hiding this comment

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

At the moment, this test is checking that plotting all symbols as circles (c) work. A better test would be to test a mix of symbols such as circles (c), triangles (t), squares (s), etc (like your example in #1076 (comment)).

@weiji14 weiji14 added the enhancement Improving an existing feature label May 18, 2021
@maxrjones maxrjones added this to the 0.5.0 milestone Jun 15, 2021
@weiji14 weiji14 added this to In progress in Release v0.6.x via automation Oct 3, 2021
@weiji14 weiji14 modified the milestones: 0.5.0, 0.6.0 Oct 3, 2021
@weiji14 weiji14 modified the milestones: 0.6.0, 0.7.0 Mar 13, 2022
@weiji14 weiji14 added this to In progress in Release v0.7.x via automation May 5, 2022
@weiji14 weiji14 removed this from In progress in Release v0.6.x May 5, 2022
@seisman seisman modified the milestones: 0.7.0, 0.8.0 Jun 17, 2022
@seisman seisman removed this from In progress in Release v0.7.x Jul 10, 2022
@seisman seisman modified the milestones: 0.8.0, 0.9.0 Dec 11, 2022
@seisman seisman modified the milestones: 0.9.0, 0.10.0 Mar 16, 2023
@weiji14
Copy link
Member

weiji14 commented Jun 8, 2023

@core-man, ok if one of us picks this PR up again? There's been quite a few changes to the plot function including renaming of aliases (see https://github.com/GenericMappingTools/pygmt/commits/v0.9.0/pygmt/src/plot.py), so we might need to resolve a few conflicts first.

@weiji14 weiji14 removed this from the 0.10.0 milestone Aug 24, 2023
@seisman seisman added this to the 0.12.0 milestone Dec 11, 2023
@seisman seisman removed this from the 0.12.0 milestone Feb 26, 2024
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.

None yet

4 participants