Python Inheritance suitability of using subclass to produce plot after setting plot properties in parent
Question: I am trying to write a simple Python matplotlib plotting Class that will set
up formatting of the plot as I would like. To do this, I am using a class and
a subclass. The parent generates an axis and figure, then sets all axis
properties that I would like. Then the `child` generates the plot itself -
scatter plot, line, etc. - and saves the plot to an output file.

Here is what I have come up with for the purposes of this question (the plot
itself is based on [this
code](http://matplotlib.org/examples/pylab_examples/simple_plot.html)):

    
    
    import matplotlib.pyplot as plt
    import numpy as np
    
    class myplot():
    
        def __init__(self,dims,padd):
            self.fig = plt.figure(figsize=(8.5, 11))
            self.ax = self.fig.add_axes(dims)
            self.pad = padd
    
        def ax_prop(self):
            self.ax.set_axisbelow(True)
            self.ax.tick_params(axis='x', pad=self.pad, which='both')
    
    class plotter(myplot):
        def __init__(self,dims,padd,x,y):
            myplot.__init__(self,dims,padd)
            self.x = x
            self.y = y
    
        def mk_p(self):
            self.ax.plot(self.x, self.y, linestyle = '-')
            plt.savefig('Outfile.png', facecolor=self.fig.get_facecolor(), dpi = 300)
            plt.show()
    
    if __name__ == "__main__":
        x = np.arange(0.0, 2.0, 0.01)
        y = np.sin(2*np.pi*x)
        propr = [0.60, 0.2, 0.2, 0.25]; padding =5 
        plt_instance = myplot(propr,padding)
        plt_instance.ax_prop()
        pl_d = plotter(propr,padding,x,y)
        pl_d.mk_p()
    

I'm tying to base this on the following:

    
    
    The child must have all the properties of the parent.
    

Therefore, the `child` class `plotter()` must inherit the:

    
    
    ax, and all its customized properties
    fig
    

from the parent (`myplot()`) class. The following may change in the `Child`
class:

  1. type of plot - scatter, line, etc.
  2. any properties of the type of plot - `markersize`, `linestyle`, etc.

but the `matplotlib` figure and axis objects (`fig`,`ax`) will always be
required before plotting an input set of numbers.

**Question:**

Is this a _correct_ usage of Python inheritance or is the child class
superfluous in this case? If so, was there a place where the reasoning for a
subclass was not consistent with object oriented programming (I'm having
difficulty convincing myself of this)?


Answer: I think the main issue is that your subclass violates the [Liskov Substitution
Principle](https://en.wikipedia.org/wiki/Liskov_substitution_principle). Also
see [here](https://lostechies.com/derickbailey/2009/02/11/solid-development-
principles-in-motivational-pictures/) for nice pictures of SOLID principles.
You can't substitute an instance of `myplot` for `plotter`, since `plotter`'s
method signature is different. You should be able to substitute in a subclass
instead of the base class. Because the signature is different, you cannot.

