1

I'm trying to use mpl_toolkits to display a radar visualization for a sonar project. It seems to compile fine on my PC, but when I run it on my Pi 3, I get the matplotlib window, but not plot. The only error message is:

Warning (from warnings module):
  File "/usr/local/lib/python3.4/dist-packages/matplotlib/projections/polar.py", line 157
    theta %= 2 * np.pi
RuntimeWarning: invalid value encountered in remainder

...with no traceback.

As I understand it, this is indicating a division by zero, but:

  1. I had a similar error on my PC, and still got a plot
  2. This doesn't explain why it works on one device, but not another.

As far as I am aware I have all the required packages, after I installed python-cairocffi. Help?

More details:

  • Python3.6 on PC, Python3.4 on Pi
  • Pi 3
  • Raspbian Jessie

code used:

"""
Axis within rectangular frame
based on demo_curvelinear_grid.py.
"""
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.axisartist.angle_helper as angle_helper
from matplotlib.projections import PolarAxes
from matplotlib.transforms import Affine2D
from mpl_toolkits.axisartist import SubplotHost
from mpl_toolkits.axisartist import GridHelperCurveLinear


def curvelinear_test2(fig):
    """
    polar projection, but in a rectangular box.
    """
    global ax1

    # rotate a bit for better orientation
    tr_rotate = Affine2D().translate(90, 0)

    # see demo_curvelinear_grid.py for details
    tr = tr_rotate + Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform()

    extreme_finder = angle_helper.ExtremeFinderCycle(20,
                                                     20,
                                                     lon_cycle=360,
                                                     lat_cycle=None,
                                                     lon_minmax=None,
                                                     lat_minmax=(0,np.inf),
                                                     )

    grid_locator1 = angle_helper.LocatorDMS(12)

    tick_formatter1 = angle_helper.FormatterDMS()

    grid_helper = GridHelperCurveLinear(tr,
                                        extreme_finder=extreme_finder,
                                        grid_locator1=grid_locator1,
                                        tick_formatter1=tick_formatter1,
                                        )

    ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper)

    fig.add_subplot(ax1)

    # Now creates floating axis

    # floating axis whose first coordinate (theta) is fixed at 0
    ax1.axis["lat"] = axis = ax1.new_floating_axis(0, 0)
    # axis.label.set_text(r"$\theta = 60^{\circ}$")
    axis.major_ticklabels.set_axis_direction("right")
    axis.label.set_visible(True)

    # floating axis whose second coordinate (r) is fixed at 6
    ax1.axis["top"].major_ticklabels.set_visible(True)
    # axis.label.set_text(r"$r = 6$")
    # axis.label.set_visible(True)


    ax1.set_aspect(1.)
    ax1.set_xlim(-15, 15)
    ax1.set_ylim(0, 20)

    ax1.grid(True)

    x = [1,2,3,4,5,6,7,8]
    y = [5,2,4,2,1,4,5,2]

    ax1.plot(x, y)

fig = plt.figure(1, figsize=(5, 5))
fig.clf()
curvelinear_test2(fig)

plt.show()

This is my first posted question, I apologize for any formatting/lack of information errors.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • I have reformatted, and tried to add more detail as to the nature of the problem. Please let me know if there is additional information needed. – Niels Huisman Apr 25 '17 at 19:22

0 Answers0