how to update grid parameters for figure & canvas created with matplotlib.figure & matplotlib.backends.backend_qt5agg

22 views Asked by At

I need to update grid parameters (visible, which, axis, **kwargs) to customize the major and minor grid lines style. i tried using plt.grid(which='minor', linewidth=0.5, linestyle='dotted') but it did not work; it only works if figure and subplot was created using matplotlib.pyplot.subplots().

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as Canvas
from matplotlib.figure import Figure    

class MatplotlibWidget(QWidget):
    def __init__(self, parent=None):   
    self.canvas = Canvas(Figure(figsize=(8, 6)))
    self.axes = self.canvas.figure.subplots()
1

There are 1 answers

0
Hannibal On BEST ANSWER

i got this working by invoking grid() method of the axes to configure grid lines. refer to documentation here: matplotlib.axes.Axes.grid

axes.grid(which='minor', linewidth=0.5, linestyle='dotted')