Repository: vispy/vispy

Issue:
Wrong scale on X and Y axis LinePlot
On lineplot initialisation the X and Y axis will often be incorrect by 1 (major) division. This can be fixed by scrolling which updates the axis numbers. This problem doesn't happen every time however.

Example:

`self.x = np.linspace(0, 1000, 1000)
self.y = np.linspace(0, 50000, 1000)`

will sometimes produce a line from -10k to 40k rather than 0 to 50k


`

        def initGraph(self):

        self.line = None
        self.fig = None
        self.fig = vp.Fig(size=(1200, 380), position=(-40, -50))
        self.fig.create_native()
        self.fig.native.setParent(self.ui.canvas)

        self.x = np.linspace(0, 1000, 1000)
        self.y = np.linspace(0, 50000, 1000)

        self.line = self.fig[0, 0].plot((self.x, self.y), width=1, color='blue', xlabel='',
                                        ylabel='', marker_size=-10)
        self.line._line.method = 'agg'

`


Discussion:
Currently looking in to this. Here is a complete test case:
```
import numpy as np
import vispy.plot as vp
from vispy import app
x = np.linspace(0, 1000, 1000)
y = np.linspace(0, 50000, 1000)
line = None
fig = None
fig = vp.Fig(size=(1200, 380), position=(-40, -50))
fig.create_native()
#fig.native.setParent(ui.canvas)

x = np.linspace(0, 1000, 1000)
y = np.linspace(0, 50000, 1000)

line = fig[0, 0].plot((x, y), width=1, color='blue', xlabel='',
                                ylabel='', marker_size=-10)
line._line.method = 'agg'
#fig[0, 0].xaxis._view_changed()

app.run()
```

The issue seems to be some kind of race condition on the transform changing. If you uncomment the commented line above you *should* consistently get the right ranges on load. I'm still looking for a long term fix.

Edit: ...nevermind. Still inconsistent.

Resolving patch:
diff --git a/vispy/scene/widgets/grid.py b/vispy/scene/widgets/grid.py
--- a/vispy/scene/widgets/grid.py
+++ b/vispy/scene/widgets/grid.py
@@ -5,7 +5,9 @@
 from __future__ import division
 import numpy as np
 
+from vispy.geometry import Rect
 from .widget import Widget
+from .viewbox import ViewBox
 
 from ...ext.cassowary import (SimplexSolver, expression,
                               Variable, WEAK, REQUIRED,
@@ -25,7 +27,6 @@ class Grid(Widget):
         Keyword arguments to pass to `Widget`.
     """
     def __init__(self, spacing=6, **kwargs):
-        from .viewbox import ViewBox
         self._next_cell = [0, 0]  # row, col
         self._cells = {}
         self._grid_widgets = {}
@@ -235,7 +236,6 @@ def add_view(self, row=None, col=None, row_span=1, col_span=1,
         **kwargs : dict
             Keyword arguments to pass to `ViewBox`.
         """
-        from .viewbox import ViewBox
         view = ViewBox(**kwargs)
         return self.add_widget(view, row, col, row_span, col_span)
 
@@ -495,8 +495,11 @@ def _update_child_widget_dim(self):
             else:
                 y = np.sum(value_vectorized(self._height_grid[col][0:row]))
 
-            widget.size = (width, height)
-            widget.pos = (x, y)
+            if isinstance(widget, ViewBox):
+                widget.rect = Rect(x, y, width, height)
+            else:
+                widget.size = (width, height)
+                widget.pos = (x, y)
 
     @property
     def _widget_grid(self):


Test patch: