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 intensity for plot #1065

Merged
merged 23 commits into from
Mar 23, 2021

Conversation

core-man
Copy link
Member

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

Description of proposed changes

Pass a NumPy array to intensity (similar to the x, y, size parameters) for the plot method when we use x/y as the input. (See #891 for details)

Currently, we can have two ways to specify an intensity/intensities.

  • Simply give a constant intensity like intensity=0.5, which works for both x/y and data input. This is similar to -I0.5 in the GMT command line.
  • Set intensity=True, and read intensities from an input file or from a 2D NumPy array, which is only for the data parameter. This is similar to -I in the GMT command line.

So, when we want to change the intensities for different points, we can only use the data parameter now. This PR tries to pass an array to intensity so that we can set different intensities when we use x/y as point input. This way will not work for data input.

Related to #891

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 15, 2021 11:35
@core-man core-man changed the title Allow passing a numpy array as intensity for plot and plot3d WIP: Allow passing a numpy array as intensity for plot and plot3d Mar 15, 2021
@seisman
Copy link
Member

seisman commented Mar 15, 2021

I haven't reviewed your codes, but please do plot and plot3d in two PRs.

@core-man
Copy link
Member Author

core-man commented Mar 15, 2021

I haven't reviewed your codes, but please do plot and plot3d in two PRs.

Okay. BTW, I only added a NumPy array support for intensity now to test if it works (it works). More work need to be done (e.g., add test).

@core-man core-man changed the title WIP: Allow passing a numpy array as intensity for plot and plot3d WIP: Allow passing a numpy array as intensity for plot Mar 15, 2021
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.

Just one comment for now :)

Okay. BTW, I only added a NumPy array support for intensity now to test if it works (it works). More work need to be done (e.g., add test).

Yes, time for you to pick up unit testing! I'm currently revamping the plot testing ways at #1036 but you can start first and we'll refactor later. The PyGMT guidelines are at https://github.com/GenericMappingTools/pygmt/blob/v0.3.1/CONTRIBUTING.md#testing-plots, but if you're new to (or need a refresher on) testing, I found https://automationpanda.com/python/ to be a good resource to understand the 'why' and 'how' of testing.

pygmt/src/plot.py Outdated Show resolved Hide resolved
@core-man core-man changed the title WIP: Allow passing a numpy array as intensity for plot WIP: Allow passing an array as intensity for plot Mar 17, 2021
@core-man
Copy link
Member Author

A test with an array intensity is added (9adf272), referring to test_plot_varying_transparency().

def test_plot_varying_transparency():

@core-man core-man changed the title WIP: Allow passing an array as intensity for plot Allow passing an array as intensity for plot Mar 17, 2021
pygmt/tests/test_plot.py Outdated Show resolved Hide resolved
@core-man
Copy link
Member Author

Two related questions:

  1. The documentation for color parameter needs a revision in the API page of plot (also plot3d)?

color (str) – Select color or pattern for filling of symbols or polygons. Default is no fill.

color can also be a 1D array just like the sizes parameter when we use x/y parameters. See the last example in Plotting data points.

  1. We can now input array-like sizes, color, intensity. Shall we support array-like symbols?

The format of the input file of plot is (-S and -I):

x y [ z ] [ size ] [ symbol-parameters ] [ intensity ] [ symbol ]

See an example with x y z size intensity symbol

gmt begin symbols png
gmt makecpt -Chot -T0/3/1
gmt plot -R0/5/0/1 -JX5c/1c -BWSne -Bxa1 -Bya0.5 -S -C -I -W1p,black << EOF
1  0.5   0   0.3  1  c
2  0.5   1   0.8 -1  t
3  0.5   2   0.5  0  i
EOF
gmt end show

symbols

pygmt/src/plot.py Outdated Show resolved Hide resolved
@seisman
Copy link
Member

seisman commented Mar 17, 2021

  1. We can now input array-like sizes, color, intensity. Shall we support array-like symbols?

Yes, please open a new feature request.

pygmt/tests/test_plot.py Outdated Show resolved Hide resolved
@core-man core-man requested a review from seisman March 21, 2021 16:14
pygmt/src/plot.py Outdated Show resolved Hide resolved
pygmt/src/plot.py Outdated Show resolved Hide resolved
pygmt/tests/test_plot.py Outdated Show resolved Hide resolved
@seisman seisman added this to the 0.4.0 milestone Mar 22, 2021
@core-man core-man marked this pull request as draft March 22, 2021 12:12
@core-man core-man marked this pull request as ready for review March 22, 2021 12:13
Copy link
Member

@seisman seisman left a comment

Choose a reason for hiding this comment

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

This PR looks good to me. We will merge this PR if others have no objections.

@seisman seisman added the final review call This PR requires final review and approval from a second reviewer label Mar 22, 2021
Copy link
Member

@maxrjones maxrjones left a comment

Choose a reason for hiding this comment

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

Nice work!

@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Mar 22, 2021
@seisman seisman changed the title Allow passing an array as intensity for plot Allow passing a array as intensity for plot Mar 23, 2021
@seisman seisman merged commit 2600006 into GenericMappingTools:master Mar 23, 2021
@core-man core-man deleted the intensity-np-array branch March 23, 2021 02:54
@core-man core-man mentioned this pull request Apr 15, 2021
5 tasks
@weiji14 weiji14 changed the title Allow passing a array as intensity for plot Allow passing an array as intensity for plot May 2, 2021
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
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.

5 participants