Skip to content

axis3d.py : new inheritance and overriden methods for Yaxis class #21927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions lib/mpl_toolkits/mplot3d/axis3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def tick_update_position(tick, tickxs, tickys, labelpos):
tick.gridline.set_data(0, 0)


class Axis(maxis.XAxis):
class Axis(maxis.Axis):
"""An Axis class for the 3D plots."""
# These points from the unit cube make up the x, y and z-planes
_PLANES = (
Expand Down Expand Up @@ -516,21 +516,44 @@ def v_interval(self, minmax):
# Use classes to look at different data limits


class XAxis(Axis):
class XAxis(Axis, maxis.XAxis):
get_view_interval, set_view_interval = maxis._make_getset_interval(
"view", "xy_viewLim", "intervalx")
get_data_interval, set_data_interval = maxis._make_getset_interval(
"data", "xy_dataLim", "intervalx")


class YAxis(Axis):
class YAxis(Axis, maxis.YAxis):
get_view_interval, set_view_interval = maxis._make_getset_interval(
"view", "xy_viewLim", "intervaly")
get_data_interval, set_data_interval = maxis._make_getset_interval(
"data", "xy_dataLim", "intervaly")


class ZAxis(Axis):
def get_tick_space(self):
ends = mtransforms.Bbox.from_bounds(0, 0, 1, 1)
ends = ends.transformed(self.axes.transAxes -
self.figure.dpi_scale_trans)
length = ends.height * 72
# The spacing must be the same as in the XAxis method (3).
size = self._get_tick_label_size('y') * 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICS, using 'y' is the only difference to before. In that case, shouldn't we fix the original Axis.get_tickspace to use self._get_tick_label_size(self.axis_name) (and define axis_name on the 3d Axis classes)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the only difference to before is in fact not the use of 'y' but the multiplication by 3. We can see in the axis.py file that the method get_tick_space in the XAxis class has the line size = self._get_tick_label_size('x') * 3, whereas in the YAxis class the same method has the line size = self._get_tick_label_size('y') * 2

The reason for this change in coefficient is the aspect of a 2D plot : it requires less space to write labels like this :

label    (Y labels)
label
label 

Than like this :
label label label (X labels)

However, in 3D plots the Y axis is like another X axis : hence the overriding of the method, even though it's just for one digit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification. It seems we should turn the factor into a class variable then.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're probably right, it would be more convenient. Oh and I also had a question : would you know why thecodecov/progect/tests omitted the src file in this PR ? I'm new to github and matplotlib, I don't really understand how all of it works.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to admit, that I don't understand Codecov either. It sometimes appears to do weird things.

if size > 0:
return int(np.floor(length / size))
else:
return 2**31 - 1

def clear(self):
#The padding of the Yticks must be the same as for the XTicks.
super().clear()
self.majorTicks[0].label1.set(horizontalalignment='center',
verticalalignment='top')
self.minorTicks[0].label1.set(horizontalalignment='center',
verticalalignment='top')
self.majorTicks[0].label2.set(horizontalalignment='center',
verticalalignment='top')
self.minorTicks[0].label2.set(horizontalalignment='center',
verticalalignment='top')

class ZAxis(Axis, maxis.XAxis):
get_view_interval, set_view_interval = maxis._make_getset_interval(
"view", "zz_viewLim", "intervalx")
get_data_interval, set_data_interval = maxis._make_getset_interval(
Expand Down