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

Problems with hold method behavior #51

Open
kojix2 opened this issue Aug 3, 2021 · 0 comments
Open

Problems with hold method behavior #51

kojix2 opened this issue Aug 3, 2021 · 0 comments

Comments

@kojix2
Copy link
Member

kojix2 commented Aug 3, 2021

Recent changes have caused the axis position to change depending on whether a label or title is present. This sometimes caused the hold to not work correctly. This problem is related to #22 . In julia, the state seems to be maintained by the global variables ctx and plt.

case1

  • Use the hash returned by hold as is.
  • The line plot drawn later deviates from y=0.
require 'numo/narray'
require 'gr/plot'
DFloat = Numo::DFloat
NMath = Numo::NMath

x = DFloat.linspace(0, 10, 500)
y = NMath.sin(x**2) * NMath.exp(-x)
kw = {title: "Example plot", xlabel: "X", ylabel: "Y", update: false}

GR.beginprint("img.png") do
  GR.plot(x, y, kw.clone)
  k = GR.hold
  k.merge!({update: false})
  GR.plot(x, -2 * NMath.exp(x)**-1, k)
  GR.plot(x, 2 * NMath.exp(x)**-1, k)
  GR.updatews
end

img

case2

  • Add title and label to the hash returned by hold.
  • The line plot drawn later will be displayed correctly.
require 'numo/narray'
require 'gr/plot'
DFloat = Numo::DFloat
NMath = Numo::NMath

x = DFloat.linspace(0, 10, 500)
y = NMath.sin(x**2) * NMath.exp(-x)
kw = {title: "Example plot", xlabel: "X", ylabel: "Y", update: false}

GR.beginprint("img.png") do
  GR.plot(x, y, kw.clone) # should be fiexed
  k = GR.hold
  k.merge!(kw)
  GR.plot(x, -2 * NMath.exp(x)**-1, k)
  GR.plot(x, 2 * NMath.exp(x)**-1, k)
  GR.updatews
end

img

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant