Python matplotlib.pyplot.get_backend() Examples

The following are 8 code examples of matplotlib.pyplot.get_backend(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib.pyplot , or try the search function .
Example #1
Source File: test_latexipy.py    From latexipy with MIT License 5 votes vote down vote up
def test_revert():
    with patch('matplotlib.rcParams.update') as mock_update, \
            patch('matplotlib.pyplot.switch_backend') as mock_switch:
        lp.latexify()
        lp.revert()
        mock_update.assert_called_with(dict(plt.rcParams))
        mock_switch.assert_called_with(plt.get_backend()) 
Example #2
Source File: utilities.py    From HARK with Apache License 2.0 5 votes vote down vote up
def find_gui():
    """ Quick fix to check if matplotlib is running in a GUI environment.

    Returns
    -------
    bool: Boolean
          True if it's a GUI environment, False if not.
    """
    try:
        import matplotlib.pyplot as plt
    except:
        return False
    if plt.get_backend() == 'Agg':
        return False
    return True 
Example #3
Source File: CurveXtractor.py    From qkit with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, xdata = [0], ydata = [0], zdata = [0], smoothness = 0.1):
        """
        Inits CurveXtractor with xdata, ydata, zdata and smoothness of the splines.
        
        Args:
            xdata:      xaxis data
            ydata:      yaxis data
            zdata:      2d matix of zdata
            smoothness: smoothness of the spline (can also be changed later on in the procedure).
        """
        if plt.get_backend().find("nbagg") == -1:
            print("Module requires using the widget backend for matplotlib.\nActivate with %matplotlib widget.")
            return
        self.xvals = 0 
        self.yvals = 0 
        self.zvals = 0
        self._smoothness = smoothness
        
        self._status = True
        self._infotxt = 0
        
        self._points_x = []
        self._points_y = []
        self._curve_x = []
        self._curve_y = []
        self._x_results = []
        self._y_results = []
        
        self._col = ["w", "C1", "C3", "C6", "C8"]
        self._pointplots = [[]]
        self._curveplots = []
        self._result_plots = []
        self._xlim = (min(xdata), max(xdata))
        self._ylim = (min(ydata), max(ydata))
        
        self._splines = [] 
Example #4
Source File: hand_eye_calibration_plotting_tools.py    From hand_eye_calibration with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def plot_alignment_errors(errors_position, rmse_pose, errors_orientation,
                          rmse_orientation, blocking=True):
  assert np.array_equal(errors_position.shape, errors_orientation.shape)

  num_error_values = errors_position.shape[0]

  title_position = 1.05
  fig = plt.figure()
  a1 = fig.add_subplot(2, 1, 1)
  fig.suptitle("Alignment Evaluation", fontsize='24')
  a1.set_title(
      "Red = Position Error Norm [m] - Black = RMSE", y=title_position)
  plt.plot(errors_position, c='r')
  plt.plot(rmse_pose * np.ones((num_error_values, 1)), c='k')
  a2 = fig.add_subplot(2, 1, 2)
  a2.set_title(
      "Red = Absolute Orientation Error [Degrees] - Black = RMSE", y=title_position)
  plt.plot(errors_orientation, c='r')
  plt.plot(rmse_orientation * np.ones((num_error_values, 1)), c='k')
  if plt.get_backend() == 'TkAgg':
    mng = plt.get_current_fig_manager()
    max_size = mng.window.maxsize()
    max_size = (max_size[0], max_size[1] * 0.45)
    mng.resize(*max_size)
  fig.tight_layout()
  plt.subplots_adjust(left=0.025, right=0.975, top=0.8, bottom=0.05)
  plt.show(block=blocking) 
Example #5
Source File: runner.py    From xrt with MIT License 5 votes vote down vote up
def start_jobs():
    """
    Restores the plots if requested and if the persistent files exist and
    starts the qt timer of the 1st plot.
    """
    for plot in _plots:
        if plot.persistentName:
            plot.restore_plots()
        plot.fig.canvas.set_window_title(plot.title)

    runCardVals.iteration = np.long(0)
    noTimer = len(_plots) == 0 or\
        (plt.get_backend().lower() in (x.lower() for x in
                                       mpl.rcsetup.non_interactive_bk))
    if noTimer:
        print("The job is running... ")
        while True:
            msg = '{0} of {1}'.format(
                runCardVals.iteration+1, runCardVals.repeats)
            if os.name == 'posix':
                sys.stdout.write("\r\x1b[K " + msg)
            else:
                sys.stdout.write("\r  ")
                print(msg+' ')
            sys.stdout.flush()
            res = dispatch_jobs()
            if res:
                return
    else:
        plot = _plots[0]
        plot.areProcessAlreadyRunning = False
        plot.timer = plot.fig.canvas.new_timer()
        plot.timer.add_callback(plot.timer_callback)
        plot.timer.start() 
Example #6
Source File: renderer.py    From holoviews with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def load_nb(cls, inline=True):
        """
        Initialize matplotlib backend
        """
        import matplotlib.pyplot as plt
        backend = plt.get_backend()
        if backend not in ['agg', 'module://ipykernel.pylab.backend_inline']:
            plt.switch_backend('agg') 
Example #7
Source File: test_pyplot.py    From imgviz with MIT License 5 votes vote down vote up
def test_pyplot():
    backend = plt.get_backend()
    plt.switch_backend("agg")

    x = y = [0, 1, 2]
    plt.plot(x, y)

    plt.switch_backend(backend)

    img = imgviz.io.pyplot_to_numpy()
    assert isinstance(img, np.ndarray)
    assert img.ndim == 3 
Example #8
Source File: trajectory.py    From imgviz with MIT License 4 votes vote down vote up
def plot_trajectory(
    transforms, is_relative=False, mode="xz", style="b.", axis=True,
):
    """Plot the trajectory using transform matrices

    Parameters
    ----------
    transforms: numpy.ndarray
        transform matrices with the shape of [N, 4, 4]
        where N is the # of poses.
    is_relative: bool
        True for relative poses. default: False.
    mode: str
        x and y axis of trajectory. default: 'xz' following kitti format.
    style: str
        style of ploting, default: 'b.'
    axis: bool
        False to disable axis.

    Returns
    -------
    dst: numpy.ndarray
        trajectory

    """
    import matplotlib.pyplot as plt

    if is_relative:
        for i in range(1, len(transforms)):
            transforms[i] = transforms[i - 1].dot(transforms[i])

    if len(mode) != 2 and all(x in "xyz" for x in mode):
        raise ValueError("Unsupported mode: {}".format(mode))

    x = []
    y = []
    index_x = "xyz".index(mode[0])
    index_y = "xyz".index(mode[1])
    for T in transforms:
        translate = tf.translation_from_matrix(T)
        x.append(translate[index_x])
        y.append(translate[index_y])

    # swith backend to agg for supporting no display mode
    backend = plt.get_backend()
    plt.switch_backend("agg")

    plt.plot(x, y, style)

    if not axis:
        plt.axis("off")

    dst = pyplot_to_numpy()
    plt.close()

    # switch back backend
    plt.switch_backend(backend)

    return dst