Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Draw 3D gridlines below axis lines, labels, text, and ticks #25482

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

Merged
merged 1 commit into from
Apr 29, 2023
Merged
Show file tree
Hide file tree
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
245 changes: 131 additions & 114 deletions lib/matplotlib/tests/baseline_images/test_figure/tightbbox_box_aspect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def test_EllipseCollection():
ax.autoscale_view()


@image_comparison(['polycollection_close.png'], remove_text=True)
@image_comparison(['polycollection_close.png'], remove_text=True, style='mpl20')
def test_polycollection_close():
from mpl_toolkits.mplot3d import Axes3D # type: ignore

Expand Down
5 changes: 4 additions & 1 deletion lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,10 @@ def draw(self, renderer):
# Draw panes first
for axis in self._axis_map.values():
axis.draw_pane(renderer)
# Then axes
# Then gridlines
for axis in self._axis_map.values():
axis.draw_grid(renderer)
# Then axes, labels, text, and ticks
for axis in self._axis_map.values():
axis.draw(renderer)

Expand Down
59 changes: 39 additions & 20 deletions lib/mpl_toolkits/mplot3d/axis3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,26 +445,6 @@ def draw(self, renderer):
self.offsetText.set_ha(align)
self.offsetText.draw(renderer)

if self.axes._draw_grid and len(ticks):
# Grid points where the planes meet
xyz0 = np.tile(minmax, (len(ticks), 1))
xyz0[:, index] = [tick.get_loc() for tick in ticks]

# Grid lines go from the end of one plane through the plane
# intersection (at xyz0) to the end of the other plane. The first
# point (0) differs along dimension index-2 and the last (2) along
# dimension index-1.
lines = np.stack([xyz0, xyz0, xyz0], axis=1)
lines[:, 0, index - 2] = maxmin[index - 2]
lines[:, 2, index - 1] = maxmin[index - 1]
self.gridlines.set_segments(lines)
gridinfo = info['grid']
self.gridlines.set_color(gridinfo['color'])
self.gridlines.set_linewidth(gridinfo['linewidth'])
self.gridlines.set_linestyle(gridinfo['linestyle'])
self.gridlines.do_3d_projection()
self.gridlines.draw(renderer)

# Draw ticks:
tickdir = self._get_tickdir()
tickdelta = deltas[tickdir] if highs[tickdir] else -deltas[tickdir]
Expand Down Expand Up @@ -502,6 +482,45 @@ def draw(self, renderer):
renderer.close_group('axis3d')
self.stale = False

@artist.allow_rasterization
def draw_grid(self, renderer):
if not self.axes._draw_grid:
return

renderer.open_group("grid3d", gid=self.get_gid())

ticks = self._update_ticks()
if len(ticks):
# Get general axis information:
info = self._axinfo
index = info["i"]

mins, maxs, _, _, _, highs = self._get_coord_info(renderer)

minmax = np.where(highs, maxs, mins)
maxmin = np.where(~highs, maxs, mins)

# Grid points where the planes meet
xyz0 = np.tile(minmax, (len(ticks), 1))
xyz0[:, index] = [tick.get_loc() for tick in ticks]

# Grid lines go from the end of one plane through the plane
# intersection (at xyz0) to the end of the other plane. The first
# point (0) differs along dimension index-2 and the last (2) along
# dimension index-1.
lines = np.stack([xyz0, xyz0, xyz0], axis=1)
lines[:, 0, index - 2] = maxmin[index - 2]
lines[:, 2, index - 1] = maxmin[index - 1]
self.gridlines.set_segments(lines)
gridinfo = info['grid']
self.gridlines.set_color(gridinfo['color'])
self.gridlines.set_linewidth(gridinfo['linewidth'])
self.gridlines.set_linestyle(gridinfo['linestyle'])
self.gridlines.do_3d_projection()
self.gridlines.draw(renderer)

renderer.close_group('grid3d')

# TODO: Get this to work (more) properly when mplot3d supports the
# transforms framework.
def get_tightbbox(self, renderer=None, *, for_layout_only=False):
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading