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

Figure.plot fails to plot lines correctly #255

Closed
seisman opened this issue Nov 29, 2018 · 7 comments · Fixed by #547
Closed

Figure.plot fails to plot lines correctly #255

seisman opened this issue Nov 29, 2018 · 7 comments · Fixed by #547
Labels
bug Something isn't working upstream Bug or missing feature of upstream core GMT
Milestone

Comments

@seisman
Copy link
Member

seisman commented Nov 29, 2018

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
@leouieda leouieda added the bug Something isn't working label Jan 22, 2019
@seisman
Copy link
Member Author

seisman commented Feb 6, 2019

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.

@seisman
Copy link
Member Author

seisman commented Feb 6, 2019

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")

@seisman
Copy link
Member Author

seisman commented Feb 18, 2019

@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.

@leouieda
Copy link
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.

@weiji14
Copy link
Member

weiji14 commented Nov 8, 2019

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.

@seisman
Copy link
Member Author

seisman commented May 14, 2020

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

@weiji14
Copy link
Member

weiji14 commented Jun 18, 2020

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
Labels
bug Something isn't working upstream Bug or missing feature of upstream core GMT
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants