Skip to content

Figure.plot fails to plot lines correctly #255

Closed

Description

@seisman

Description of the problem

Figure.plot() doesn't plot simple lines correctly.

Full code that generated the error

import pygmt

fig = pygmt.Figure()
fig.basemap(J="X8c/8c", R="-10/10/0/10", B=True)
fig.plot(x=[0.0, 0.0], y=[0, 10], W="1p,gray,-")
fig.plot(x=[5.0, 5.0], y=[2, 8], W="1p,gray,-")
fig.plot(x=[3.0, 8.0], y=[0, 10], W="1p,gray,-")
fig.show(method="external")

Output plot
plot-lines-fail

Only the first line is correct. The other two lines are wrong.

System information

  • Operating system: macOS
  • Python installation (Anaconda, system, ETS): Anaconda
  • Version of GMT: 6.0.0_15a9160
  • Version of Python: 3.7.0
  • Version of this package: latest
  • If using conda, paste the output of conda list below

Activity

  1. added
    bug
    on Jan 22, 2019
  2. seisman commented on Feb 6, 2019

    @seisman
    MemberAuthor

    I modified the code above to plot symbols instead lines:

    import pygmt
    
    fig = pygmt.Figure()
    fig.basemap(J="X8c/8c", R="-10/10/0/10", B=True)
    fig.plot(x=[0.0, 0.0], y=[0, 10], W="1p,gray,-", style='c1c')
    fig.plot(x=[5.0, 5.0], y=[2, 8], W="1p,gray,-", style='t1c')
    fig.plot(x=[3.0, 8.0], y=[0, 10], W="1p,gray,-", style='+1c')
    fig.savefig("lines.png")
    

    image

    The symbols are correctly plotted. It seems that the input passed to plot is correct.

  3. seisman commented on Feb 6, 2019

    @seisman
    MemberAuthor

    Using data instead of x and y also works.

    import pygmt
    import numpy as np
    
    fig = pygmt.Figure()
    fig.basemap(J="X8c/8c", R="-10/10/0/10", B=True)
    fig.plot(data=np.column_stack([[0.0, 0.0], [0, 10]]), W="1p,gray,-")
    fig.plot(data=np.column_stack([[5.0, 5.0], [2, 8]]), W="1p,gray,-")
    fig.plot(data=np.column_stack([[3.0, 8.0], [0, 10]]), W="1p,gray,-")
    fig.savefig("lines.png")
    
  4. seisman commented on Feb 18, 2019

    @seisman
    MemberAuthor

    @leouieda I think we should make this issue a high priority, since plot lines is the most used feature.

    I tried to find the cause but failed and got totally confused how pygmt sends virtual file to gmt.

  5. leouieda commented on Feb 19, 2019

    @leouieda
    Member

    I agree. I'm finishing #269 and I'll get on this. The whole low-level wrapper needs a refactor as well and some documentation. I wonder if GMT is looking for different things in the given data depending on what kind of plot it is.

  6. weiji14 commented on Nov 8, 2019

    @weiji14
    Member

    The problem is that the object in x are floats, and those in y are integers. I.e. this works:

    import pygmt 
    fig = pygmt.Figure() 
    fig.basemap(J="X8c/8c", R="-10/10/0/10", B=True) 
    fig.plot(x=[0.0, 0.0], y=[0.0, 10.0], W="1p,gray,-") 
    fig.plot(x=[5.0, 5.0], y=[2.0, 8.0], W="1p,gray,-") 
    fig.plot(x=[3.0, 8.0], y=[0.0, 10.0], W="1p,gray,-") 
    fig.show(method="external")

    lines

    I've opened up a pull request at #376 to tackle #321 (comment) and could fix this too (killing two birds with one stone), it would be a matter of casting everything in the list to a float once it is a numpy array (so that the data type is consistent). Edit: will maybe fix this another time.

  7. added
    upstream
    on May 14, 2020
  8. added this to the 0.2.0 milestone on May 14, 2020
  9. seisman commented on May 14, 2020

    @seisman
    MemberAuthor

    The issue is caused by a GMT bug. See GenericMappingTools/gmt#3330 for the detailed bug report. The bug was already fixed in PR GenericMappingTools/gmt#3331 and the script above should work with the upcoming GMT 6.1.0 release.

    I added an upstream label to this issue and keep the issue opening, as I don't think we can/should do any hacking on the PyGMT side.

    Since plot() is one of the most commonly used functions, I propose that, when GMT 6.1.0 is released, we should:

    • release PyGMT v0.1.1 or v0.2.0, and bump the minimum required GMT version to 6.1.0
    • add the example script to the test
  10. weiji14 commented on Jun 18, 2020

    @weiji14
    Member

    I just hit this problem when plotting some lines, it took me a while to figure out why I had strange horizontal lines (because the bug example above was plotting vertical lines)!

    striped plot alongtrack_atl11_dh_whillans2_135

    Turns out using x of dtype 'float32' and y of dtype 'float64' messes things up too, we should add test cases for all sorts of mixed type combinations (e.g. int32/float32, float32/float64, etc) once we start using GMT 6.1. This is how it should look like:

    proper plot alongtrack_atl11_dh_whillans2_135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugupstream

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions