[Tioga-users] Gridlines

Vincent Fourmond fourmond at gmail.com
Sat May 3 02:40:57 EDT 2008


David MacMahon wrote:
> Is there an easy way to put grid lines on a plot?  By easy, I mean an
> existing method I can call with perhaps a few options like line style
> and color.

  For now, no.

> If not, I guess I'll have to write one myself that gets the axis
> information and the plot boundaries and then draws the grid lines
> individually.  Does anyone have any tips on how to do that?  How would I
> get minor tick locations?

  Seems that my additions to the axes function are not only useful to
myself ;-)... Here is the code I use in ctioga:

      # Draws the background lines associated with this axis, if
      # applicable.
      #
      # This function requires Tioga SVN -r 482
      def draw_lines(t, container)

        return unless @lines_color
        # First, getting major ticks location from tioga
        info = t.axis_information(axis_argument(t, container))

        if info['vertical']
          x0 = t.bounds_left
          x1 = t.bounds_right
        else
          y0 = t.bounds_bottom
          y1 = t.bounds_top
        end

        t.context do
          t.stroke_color = @lines_color
          t.line_width = @lines_width || info['major_tick_width']
          t.line_type = @lines_style
          for val in info['major']
            if info['vertical']
              t.stroke_line(x0, val, x1, val)
            else
              t.stroke_line(val, y0, val, y1)
            end
          end
        end
      end

  There is currently no way to get minor tick location (much more
delicate to extract from the C level than the major ticks). I probably
should give it a try, though.

  Cheers,

	Vincent


More information about the Tioga-users mailing list