From 5247c98932c747ff163c6c69b475b2516bc38ce1 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 29 Aug 2020 16:33:07 +0200 Subject: interrupts-graph.py: fix compatibility with newer library versions Address deprecation warnings. Line selection appears to be broken, but at least some graph is visible. Tested with python-matplotlib 3.3.1-1 and python-scipy 1.5.2-1. --- rare/interrupts-graph.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/rare/interrupts-graph.py b/rare/interrupts-graph.py index 8158c4f..5d0d3c5 100755 --- a/rare/interrupts-graph.py +++ b/rare/interrupts-graph.py @@ -5,13 +5,13 @@ # Wishlist: # Thicker legend lines -# Nicier smoothing +# Nicer smoothing import matplotlib.pyplot as plt import matplotlib from collections import deque, OrderedDict import numpy as np -from scipy.interpolate import spline, interp1d +from scipy.interpolate import interp1d import threading from argparse import ArgumentParser @@ -159,7 +159,7 @@ plt.grid('on') #plt.ion() # Not necessary if show() does not block. plt.show(block=False) if LOG_SCALE_BASE > 0: - plt.yscale('log', nonposy='clip', basey=LOG_SCALE_BASE) + plt.yscale('log', nonpositive='clip', base=LOG_SCALE_BASE) # Used when picking a new line or in update() update_legend = False @@ -273,7 +273,7 @@ def update(): lines[name], = plt.plot(xdata, ydata, MARKER_DEFAULT + '-', label=name, color=color) - lines[name].set_picker(5) # Make selectable + lines[name].set_pickradius(5) # Make selectable update_legend = True # Smooth curve @@ -281,7 +281,7 @@ def update(): if ydata_len > 3 and SMOOTH_CURVES: min_x = min(xdata) max_x = max(xdata) - xnew = np.linspace(min_x, max_x, (1 + max_x - min_x) * 8) + xnew = np.linspace(min_x, max_x, round(1 + max_x - min_x) * 8) #ynew = spline(xdata, ydata, xnew) # quadratic and cubic splines give too much deviations ynew = interp1d(xdata, ydata, kind='slinear')(xnew) @@ -315,7 +315,7 @@ def update(): #ymin, ymax = plt.ylim() #if ymax - ymin < largest: # plt.ylim(ymin, ymin + largest) - plt.ylim(0, largest) + plt.ylim(1, largest) # The first XRANGE items fit in the screen min_x = max(start_time - XRANGE, 0) @@ -332,21 +332,26 @@ def do_draw(): global update_legend # update legend if a line gets added, changed or removed if update_legend: + # TODO should probably create legend once and then use set_label to + # update? Right now it gives a warning: + # ./interrupts-graph.py:335: MatplotlibDeprecationWarning: Adding an + # axes using the same arguments as a previous axes currently reuses the + # earlier instance. In a future version, a new instance will always be + # created and returned. Meanwhile, this warning can be suppressed, and + # the future behavior ensured, by passing a unique label to each axes + # instance. old_legend = plt.axes().get_legend() - if old_legend: - # Undocumented API, use it to remember legend position - old_loc = old_legend._get_loc() + # Private API, use it to restore the legend position. + old_loc = old_legend and old_legend._loc or 'upper left' - legend = plt.legend(loc='upper left', + legend = plt.legend(loc=old_loc, framealpha=.5, fontsize='small') - legend.draggable() - if old_legend: - legend._set_loc(old_loc) + legend.set_draggable(True) # Enable selecting a line by clicking in the legend for line in legend.get_lines(): - line.set_picker(5) + line.set_pickradius(5) update_legend = False -- cgit v1.2.1