Skip to content

Problems with hold method behavior #51

Description

@kojix2

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions