Help with updating the limits of an axis to reflect the range of new data

Hi,

I am trying to draw a polar plot of a sonar scan. The idea being to present
it like a radar display. I have used axisartist to do the ploar plot. This
is working fine but I would like to reset the limits of the radius axis with
each new scan. I have tried a number of ways of doing this without success.
My current code to set up the plot looks like this.

and to update the plot. Like this

I have tried doing the above on the host axes and the auxiliary one and with
different parameters to the relim etc. Nothing seems to work. Before I tried
various other calls to manipulate the extremes but with the same lack of
results. Can anyone set me straight on this? I feel I must be missing
something obvious. However I find the documentation and the class
inheritance hierarchy almost impossible to follow.

Here are a couple of links to snapshots of the output.

Before
<https://dl.dropboxusercontent.com/u/84613021/Screenshot%20from%202015-03-25%2018%3A17%3A24.png>

After
<https://dl.dropboxusercontent.com/u/84613021/Screenshot%20from%202015-03-25%2018%3A18%3A30.png>

Thanks,

Roger

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Help-with-updating-the-limits-of-an-axis-to-reflect-the-range-of-new-data-tp45261.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Can you include a minimal example of the code you are using (it looks like you did include code, but it did not come through)? It is very hard to guess at what is wrong without it.

Tom

···

On Wed, Mar 25, 2015 at 2:29 PM rogerjames99 <roger@…4642…> wrote:

Hi,

I am trying to draw a polar plot of a sonar scan. The idea being to present

it like a radar display. I have used axisartist to do the ploar plot. This

is working fine but I would like to reset the limits of the radius axis with

each new scan. I have tried a number of ways of doing this without success.

My current code to set up the plot looks like this.

and to update the plot. Like this

I have tried doing the above on the host axes and the auxiliary one and with

different parameters to the relim etc. Nothing seems to work. Before I tried

various other calls to manipulate the extremes but with the same lack of

results. Can anyone set me straight on this? I feel I must be missing

something obvious. However I find the documentation and the class

inheritance hierarchy almost impossible to follow.

Here are a couple of links to snapshots of the output.

Before

<https://dl.dropboxusercontent.com/u/84613021/Screenshot%20from%202015-03-25%2018%3A17%3A24.png>

After

<https://dl.dropboxusercontent.com/u/84613021/Screenshot%20from%202015-03-25%2018%3A18%3A30.png>

Thanks,

Roger

View this message in context: http://matplotlib.1069221.n5.nabble.com/Help-with-updating-the-limits-of-an-axis-to-reflect-the-range-of-new-data-tp45261.html

Sent from the matplotlib - users mailing list archive at Nabble.com.


Dive into the World of Parallel Programming The Go Parallel Website, sponsored

by Intel and developed in partnership with Slashdot Media, is your hub for all

things parallel software development, from weekly thought leadership blogs to

news, videos, case studies, tutorials and more. Take a look and join the

conversation now. http://goparallel.sourceforge.net/


Matplotlib-users mailing list

Matplotlib-users@…1735…sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi Thomas,
I posted via nabble. It looks like something stripped the code.
Here is the bit where the axes are set up
def setup_axes(self, fig, rect):
“”"
With custom locator and formatter.
Note that the extreme values are swapped.
“”"
transform = PolarAxes.PolarTransform()
angle_ticks = [(0, r"$Right$"),
(.5*pi, r"$Forward$"),
(pi, r"$Left$")]
grid_locator1 = FixedLocator([v for v, s in angle_ticks])
tick_formatter1 = DictFormatter(dict(angle_ticks))
grid_locator2 = MaxNLocator(4)
self.grid_helper = floating_axes.GridHelperCurveLinear(transform,
extremes=(0, pi, self.sonar_limit, 0),
grid_locator1=grid_locator1,
grid_locator2=grid_locator2,
tick_formatter1=tick_formatter1,
tick_formatter2=None,
)
self.axes = floating_axes.FloatingSubplot(fig, rect, grid_helper=self.grid_helper)
self.axes.axis[“bottom”].major_ticklabels.set_rotation(180)
self.axes.axis[“left”].set_axis_direction(“bottom”)
self.axes.grid(b=True, which=‘major’, color=‘b’, linestyle=’-’)
fig.add_subplot(self.axes)

create a parasite axes whose transData in RA, cz

self.auxiliary_axes = self.axes.get_aux_axes(transform)
self.auxiliary_axes.patch = self.axes.patch # for auxiliary_axis to have a clip path as in ax
self.axes.patch.zorder=0.9 # but this has a side effect that the patch is

drawn twice, and possibly over some other

artists. So, we decrease the zorder a bit to

prevent this.

self.lines, = self.auxiliary_axes.plot(self.theta, self.radius)
and here is the bit where the plot is updated
def idleCallback(self):
global root
plotit = False
logging.debug(‘Acquire the data lock’)
self.dataLock.acquire()
if self.newSonarDataAvailable:
plotit = True
theta = self.theta[:]
radius = self.radius[:]
selfNewSonarDataAvailable = False
self.dataLock.release()

theta.insert(0, 0.)

theta.append(0.)

radius.insert(0, 0.)

radius.append(0.)

if plotit:
logging.debug(‘Plotting’)
self.lines.set_data(theta, radius)
self.axes.relim()
self.axes.autoscale_view()
self.canvas.draw()
if have also put the full code file here

As you can see I have been trying a few other things. Looks like if am missing the boat pretty comprehensively!

···

View this message in context: Re: Help with updating the limits of an axis to reflect the range of new data

Sent from the matplotlib - users mailing list archive at Nabble.com.

Yikes, that formatting is almost worse!

···

On Thu, Mar 26, 2015 at 11:53 AM rogerjames99 <roger@…4642…> wrote:

Hi Thomas,
I posted via nabble. It looks like something stripped the code.
Here is the bit where the axes are set up
def setup_axes(self, fig, rect):
“”"
With custom locator and formatter.
Note that the extreme values are swapped.
“”"
transform = PolarAxes.PolarTransform()
angle_ticks = [(0, r"Right“),
(.5*pi, r”Forward“),
(pi, r”Left")]
grid_locator1 = FixedLocator([v for v, s in angle_ticks])
tick_formatter1 = DictFormatter(dict(angle_ticks))
grid_locator2 = MaxNLocator(4)
self.grid_helper = floating_axes.GridHelperCurveLinear(transform,
extremes=(0, pi, self.sonar_limit, 0),
grid_locator1=grid_locator1,
grid_locator2=grid_locator2,
tick_formatter1=tick_formatter1,
tick_formatter2=None,
)
self.axes = floating_axes.FloatingSubplot(fig, rect, grid_helper=self.grid_helper)
self.axes.axis[“bottom”].major_ticklabels.set_rotation(180)
self.axes.axis[“left”].set_axis_direction(“bottom”)
self.axes.grid(b=True, which=‘major’, color=‘b’, linestyle=‘-’)
fig.add_subplot(self.axes)

create a parasite axes whose transData in RA, cz

self.auxiliary_axes = self.axes.get_aux_axes(transform)
self.auxiliary_axes.patch = self.axes.patch # for auxiliary_axis to have a clip path as in ax
self.axes.patch.zorder=0.9 # but this has a side effect that the patch is

drawn twice, and possibly over some other

artists. So, we decrease the zorder a bit to

prevent this.

self.lines, = self.auxiliary_axes.plot(self.theta, self.radius)
and here is the bit where the plot is updated
def idleCallback(self):
global root
plotit = False
logging.debug(‘Acquire the data lock’)
self.dataLock.acquire()
if self.newSonarDataAvailable:
plotit = True
theta = self.theta[:]
radius = self.radius[:]
selfNewSonarDataAvailable = False
self.dataLock.release()

theta.insert(0, 0.)

theta.append(0.)

radius.insert(0, 0.)

radius.append(0.)

if plotit:
logging.debug(‘Plotting’)
self.lines.set_data(theta, radius)
self.axes.relim()
self.axes.autoscale_view()
self.canvas.draw()
if have also put the full code file here

As you can see I have been trying a few other things. Looks like if am missing the boat pretty comprehensively!


View this message in context: Re: Help with updating the limits of an axis to reflect the range of new data

Sent from the matplotlib - users mailing list archive at Nabble.com.

Dive into the World of Parallel Programming The Go Parallel Website, sponsored

by Intel and developed in partnership with Slashdot Media, is your hub for all

things parallel software development, from weekly thought leadership blogs to

news, videos, case studies, tutorials and more. Take a look and join the

conversation now. http://goparallel.sourceforge.net/_______________________________________________

Matplotlib-users mailing list

Matplotlib-users@…1735…sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

And if I look at this on nabble the code looks fine, it just was not redndering in inbox. Sorry, the issues is on my end.

···

On Thu, Mar 26, 2015 at 11:54 AM Thomas Caswell <tcaswell@…287…> wrote:

Yikes, that formatting is almost worse!

On Thu, Mar 26, 2015 at 11:53 AM rogerjames99 <roger@…4642…> wrote:

Hi Thomas,
I posted via nabble. It looks like something stripped the code.
Here is the bit where the axes are set up
def setup_axes(self, fig, rect):
“”"
With custom locator and formatter.
Note that the extreme values are swapped.
“”"
transform = PolarAxes.PolarTransform()
angle_ticks = [(0, r"Right“),
(.5*pi, r”Forward“),
(pi, r”Left")]
grid_locator1 = FixedLocator([v for v, s in angle_ticks])
tick_formatter1 = DictFormatter(dict(angle_
ticks))
grid_locator2 = MaxNLocator(4)
self.grid_helper = floating_axes.GridHelperCurveLinear( transform,
extremes=(0, pi, self.sonar_limit, 0),
grid_locator1=grid_locator1,
grid_locator2=grid_locator2,
tick_formatter1=tick_ formatter1,
tick_formatter2=None,
)
self.axes = floating_axes.FloatingSubplot( fig, rect, grid_helper=self.grid_helper)
self.axes.axis[“bottom”].major_ticklabels.set_rotation( 180)
self.axes.axis[“left”].set_ axis_direction(“bottom”)
self.axes.grid(b=True, which=‘major’, color=‘b’, linestyle=‘-’)
fig.add_subplot(self.axes)

create a parasite axes whose transData in RA, cz

self.auxiliary_axes = self.axes.get_aux_axes(
transform)
self.auxiliary_axes.patch = self.axes.patch # for auxiliary_axis to have a clip path as in ax
self.axes.patch.zorder=0.9 # but this has a side effect that the patch is

drawn twice, and possibly over some other

artists. So, we decrease the zorder a bit to

prevent this.

self.lines, = self.auxiliary_axes.plot(self.

theta, self.radius)
and here is the bit where the plot is updated
def idleCallback(self):
global root
plotit = False
logging.debug(‘Acquire the data lock’)
self.dataLock.acquire()
if self.newSonarDataAvailable:
plotit = True
theta = self.theta[:]
radius = self.radius[:]
selfNewSonarDataAvailable = False
self.dataLock.release()

theta.insert(0, 0.)

theta.append(0.)

radius.insert(0, 0.)

radius.append(0.)

if plotit:
logging.debug(‘Plotting’)
self.lines.set_data(theta, radius)
self.axes.relim()
self.axes.autoscale_view()
self.canvas.draw()
if have also put the full code file here

As you can see I have been trying a few other things. Looks like if am missing the boat pretty comprehensively!


View this message in context: Re: Help with updating the limits of an axis to reflect the range of new data

Sent from the matplotlib - users mailing list archive at Nabble.com.

Dive into the World of Parallel Programming The Go Parallel Website, sponsored

by Intel and developed in partnership with Slashdot Media, is your hub for all

things parallel software development, from weekly thought leadership blogs to

news, videos, case studies, tutorials and more. Take a look and join the

conversation now. http://goparallel.sourceforge.net/_______________________________________________

Matplotlib-users mailing list

Matplotlib-users@…1735…sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Ok the last one got garbled.

My apologies to the list but here is another go.

Hi Thomas,

I posted via nabble. It looks like something stripped the code.

Here is the bit where the axes are set up

    def setup_axes(self, fig, rect):
        """
        With custom locator and formatter.
        Note that the extreme values are swapped.
        """

        transform = PolarAxes.PolarTransform()

        angle_ticks = [(0, r"$Right$"),
                       (.5*pi, r"$Forward$"),
                       (pi, r"$Left$")]
        grid_locator1 = FixedLocator([v for v, s in angle_ticks])
        tick_formatter1 = DictFormatter(dict(angle_ticks))

        grid_locator2 = MaxNLocator(4)

        self.grid_helper = floating_axes.GridHelperCurveLinear(transform,
                                            extremes=(0, pi,
self.sonar_limit, 0),
                                            grid_locator1=grid_locator1,
                                            grid_locator2=grid_locator2,
                                            tick_formatter1=tick_formatter1,
                                            tick_formatter2=None,
                                            )
        self.axes = floating_axes.FloatingSubplot(fig, rect,
grid_helper=self.grid_helper)
        self.axes.axis["bottom"].major_ticklabels.set_rotation(180)
        self.axes.axis["left"].set_axis_direction("bottom")
        self.axes.grid(b=True, which='major', color='b', linestyle='-')
        fig.add_subplot(self.axes)

        # create a parasite axes whose transData in RA, cz
        self.auxiliary_axes = self.axes.get_aux_axes(transform)

        self.auxiliary_axes.patch = self.axes.patch # for auxiliary_axis to
have a clip path as in ax
        self.axes.patch.zorder=0.9 # but this has a side effect that the
patch is
                            # drawn twice, and possibly over some other
                            # artists. So, we decrease the zorder a bit to
                            # prevent this.

        self.lines, = self.auxiliary_axes.plot(self.theta, self.radius)

and here is the bit where the plot is updated

    def idleCallback(self):
        global root
        plotit = False
        logging.debug('Acquire the data lock')
        self.dataLock.acquire()
        if self.newSonarDataAvailable:
            plotit = True
            theta = self.theta[:]
            radius = self.radius[:]
            selfNewSonarDataAvailable = False
        self.dataLock.release()
# theta.insert(0, 0.)
# theta.append(0.)
# radius.insert(0, 0.)
# radius.append(0.)
        if plotit:
            logging.debug('Plotting')
            self.lines.set_data(theta, radius)
            self.axes.relim()
            self.axes.autoscale_view()
            self.canvas.draw()

if have also put the full code file here
<https://dl.dropboxusercontent.com/u/84613021/barnaby.py>

As you can see I have been trying a few other things. Looks like if am
missing the boat pretty comprehensively!

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Help-with-updating-the-limits-of-an-axis-to-reflect-the-range-of-new-data-tp45261p45271.html
Sent from the matplotlib - users mailing list archive at Nabble.com.