0

I'm hoping that this can be answered without having to supply some code, as there are over a thousand lines and I'm not sure where the problem is.

Basically, I've created a charting class that that scrolls and updates the data as it comes in in real time. There are loads of features such as multiple y-axes, ability to pause, add vertical value lines etc etc, hence the many LOC. Nearly everything is working quite well.

I achieve the scrolling by grabbing the background then resetting and blitting when new data comes in. I have separate subcharts for each line (for the multiple y-axes) and reset the limits and call draw_artist on the main subplot only fr the x and y axes.

The problem is that as the data scrolls, depending on the current aspect, the x axis tick marks can keep changing their spacing each time new data comes in. So it might look like: 0,2,4,6,8,10,12 in one instant and then 0,5,10 the next.

Jibbity jobby
  • 1,255
  • 2
  • 12
  • 26
  • I'm thinking of using one of the solutions described here: http://stackoverflow.com/questions/12608788/changing-the-tick-frequency-on-x-or-y-axis-in-matplotlib?rq=1 The answer suggesting ax.xaxis.set_major_locator(ticker.MultipleLocator(tick_spacing)) – Jibbity jobby May 17 '16 at 08:09
  • When you redraw you can take care, among all the other stuff, of explicitly setting the x axis limits and the x axis ticks. – gboffi May 17 '16 at 08:10
  • I think that might be the problem, in that I'm letting MATPLOTLIB do this automatically and it appears to use more than just the range when calculating the tick spacing. – Jibbity jobby May 17 '16 at 08:12

1 Answers1

0

OK, I got a solution to this. When new data comes in I call the following code:

if self.tickSpacing is not None:
    self.MPLsubPlot.xaxis.set_major_locator(ticker.MultipleLocator(self.tickSpacing))
else:
    self.MPLsubPlot.xaxis.set_major_locator(ticker.AutoLocator())

self.tickSpacing is initialised to None and set to None when the user starts a pan/zoom on mouse down. On mouse up (once the pan/zoom is complete) the following function is called:

def _updateSpacing(self):
    labels = self.MPLsubPlot.xaxis.get_ticklocs()
    if len(labels) > 1:
        self.tickSpacing = labels[1] - labels[0]

This allows matplotlib to automatically determine the spacing on initial or changed aspect and then explicitly use that value on update on new data.

Jibbity jobby
  • 1,255
  • 2
  • 12
  • 26