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

Skip to content

ENH: Support minor grid in Axes3D#31527

Open
EncryptedDoom wants to merge 2 commits intomatplotlib:mainfrom
EncryptedDoom:minor_grid
Open

ENH: Support minor grid in Axes3D#31527
EncryptedDoom wants to merge 2 commits intomatplotlib:mainfrom
EncryptedDoom:minor_grid

Conversation

@EncryptedDoom
Copy link
Copy Markdown
Contributor

@EncryptedDoom EncryptedDoom commented Apr 18, 2026

PR summary

ax.grid(which='minor') was silently ignored on Axes3D — the which parameter was not handled at all, making it impossible to display minor gridlines on 3D plots without manual workarounds using ax.plot().

This PR adds minor grid support for 3D axes by:

  • Extending Axes3D.grid() to accept which ('major', 'minor', 'both') and storing minor grid state in _draw_minor_grid and _minor_grid_kwargs
  • Initialising both attributes to safe defaults in Axes3D.clear()
  • Adding Axis.draw_minor_grid() in axis3d.py which reads minor tick positions from get_minorticklocs() and draws L-shaped segments with independent line properties, mirroring the existing draw_grid() implementation
  • Calling axis.draw_minor_grid(renderer) in Axes3D.draw() after the major grid loop

Minor gridlines default to half the major linewidth with the same color and linestyle, but all properties can be overridden via kwargs.

Closes #31467

Minimum example:

import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter([1, 2, 3], [1, 2, 3], [1, 2, 3])

# Major ticks every 0.5
ax.xaxis.set_major_locator(ticker.MultipleLocator(0.5))
ax.yaxis.set_major_locator(ticker.MultipleLocator(0.5))
ax.zaxis.set_major_locator(ticker.MultipleLocator(0.5))

# Minor ticks every 0.25
ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25))
ax.yaxis.set_minor_locator(ticker.MultipleLocator(0.25))
ax.zaxis.set_minor_locator(ticker.MultipleLocator(0.25))

ax.grid(which='major', color='grey', linewidth=1.2)
ax.grid(which='minor', color='red', linewidth=0.4, linestyle=':')
plt.show()

Example output:
image

AI Disclosure

I used Claude (Anthropic) to help plan the implementation approach, understand the existing draw_grid() structure. The code changes were written and verified by me.

PR checklist

  • "closes #0000" is in the body of the PR description to link the related issue
  • new and changed code is tested
  • Plotting related features are demonstrated in an example
  • New Features and API Changes are noted with a directive and release note
  • Documentation complies with general and docstring guidelines

@EncryptedDoom EncryptedDoom force-pushed the minor_grid branch 3 times, most recently from 66a640c to 507de28 Compare April 19, 2026 07:52
`ax.grid(which='minor')` was silently ignored on Axes3D.
This commit adds full minor grid support by extending grid(),
adding draw_minor_grid() to axis3d.py, and adding a test.
@EncryptedDoom EncryptedDoom marked this pull request as ready for review April 20, 2026 18:43
@scottshambaugh
Copy link
Copy Markdown
Contributor

scottshambaugh commented Apr 23, 2026

I think this needs a lot of work to get to a robust implementation - you're duplicating a good amount of logic, only applying 3 grid style kwargs, and there is duplicated / unused code in your diff. Given these issues and the use of AI to plan the implementation I'm going to mark this for a quick close. But please feel free to ping me if you bring it to a ready state and I can remove the tag & review more thoroughly then.

@scottshambaugh scottshambaugh added the status: autoclose candidate PRs that are not yet ready for review and may be automatically closed in two weeks label Apr 23, 2026
@github-actions
Copy link
Copy Markdown

⏰ This pull request might be automatically closed in two weeks from now.

Thank you for your contribution to Matplotlib and for the effort you have put into this PR. This pull request does not yet meet the quality and clarity standards needed for an effective review. Project maintainers have limited time for code reviews, and our goal is to prioritize well-prepared contributions to keep Matplotlib maintainable.

Matplotlib maintainers cannot provide one-to-one guidance on this PR. However, if you ask focused, well-researched questions, a community member may be willing to help. 💬

To increase the chance of a productive review:

As the author, you are responsible for driving this PR, which entails doing necessary background research as well as presenting its context and your thought process. If you are a new contributor, or do not know how to fulfill these requirements, we recommend that you familiarize yourself with Matplotlib's development conventions or engage with the community via our Discourse or one of our meetings before submitting code.

If you substantially improve this PR within two weeks, leave a comment and a team member may remove the status: autoclose candidate label and the PR stays open. Cosmetic changes or incomplete fixes will not be sufficient. Maintainers will assess improvements on their own schedule. Please do not ping (@) maintainers.

@EncryptedDoom
Copy link
Copy Markdown
Contributor Author

@scottshambaugh Thank you for the detailed feedback — this is very helpful. I'll refactor the implementation to extract the shared grid-drawing logic into a common method, pass through the full set of line properties rather than just the three kwargs, and clean up the duplicated code in the diff. I'll ping you once it's ready for another look.

@scottshambaugh
Copy link
Copy Markdown
Contributor

scottshambaugh commented Apr 23, 2026

Those were specific points, but please focus on understanding how the 2D case works and how that can be mapped in a robust way onto the 3D case.

Also, your response seems to be AI generated. Do not use AI to assist in writing comments except for direct translation to English. Can you please clarify if you did here?

@EncryptedDoom
Copy link
Copy Markdown
Contributor Author

Thank you for outlining the what I need to work on and I will ensure I thoroughly understand the 2D implementation before making necessary changes to the code.
Also, I do not usually use AI to write comments except sometimes to properly explain something technical, but looking forward I will ensure I do that myself as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: autoclose candidate PRs that are not yet ready for review and may be automatically closed in two weeks topic: mplot3d

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH]: add a thinner minor grid to 3D plots

2 participants