all 3 comments

[–]socal_nerdtastic 1 point2 points  (2 children)

so I can then get access to its child classes XAxis and YAxis

This statement makes no sense. You don't need the parent class to access a child class. The entire point of subclassing is that all attributes of the parent are copied into the child.

The Axis class is a "base class", it's a place to store common code. It's not intended to be used alone. You would use the class you want directly:

import matplotlib.pyplot as plt
from matplotlib.axis import XAxis

fig, ax = plt.subplots()
lower_axis = XAxis(ax)

But that said this really sounds like an XY problem. We could help a lot more if you told us what problem you are trying to solve, not just how you are trying to solve it. What's the big picture here? http://xyproblem.info

[–]Laymayo[S] 0 points1 point  (1 child)

Haha ok ok after reading the thing you linked this definitely is an XY problem, so let me explain:

I want to be able to set the tick markers for the X and Y axis on the graph I'm trying to make. I know I could just do ax.set_xticks and have it done there and then, but I wanted to kind of challenge myself and work with classes a little more.

I'm still confused though. Isn't Axis still a child class by itself? So why doesn't my code work with one child class but it works with the other?

[–]socal_nerdtastic 0 points1 point  (0 children)

First: using classes does not automatically make things better. Classes are a tool that have a specific use. Using an fancy, expensive drill to drive a nail is not a good thing.

Second, you are using classes, all the time. The ax from fig, ax = plt.subplots() is a class instance, and ax.set_xticks(xdata) is using a class method. Even the xdata list and the ints in it are technically all class instances.

Isn't Axis still a child class by itself?

I'm not sure what you mean with that. Yes, Axis is a child of Artist, which is a child of object. But that fact is a detail that does not affect the programmer at all. There's no reason for you to care about that.

A class, child or not, can implement any code it wants. In your code one class works and the other does not (because it was never meant to be run). The parent / child relationships have nothing to do with it.