Skip to content
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

Add option to hide or show tick labels. #6018

Merged
merged 2 commits into from Mar 21, 2024

Conversation

tillahoffmann
Copy link
Contributor

@tillahoffmann tillahoffmann commented Oct 6, 2022

This PR adds a flag hide_ticks to drawing functions so tick labels can be shown. This can be useful for debugging or spatial networks, for example. The default is hide_ticks=True to ensure functionality does not change.

Edit: I'm not sure why the Circle CI test fails.
Edit: It seemed that Circle CI was failing because I hadn't updated my default branch from master to main yet.

@tillahoffmann tillahoffmann force-pushed the hide-ticks branch 2 times, most recently from d1b3c38 to 247318e Compare November 22, 2022 04:01
@dschult
Copy link
Member

dschult commented Nov 22, 2022

The axis can be set however you like after the function is done -- right?
We usually try to set good defaults but let people change whatever they like using the fundamental matplotlib tools. We usually try to avoid adding keyword args which replace matplotlib code because our code would soon become filled just reproducing all the possible options matplotlib provides. Is there something I am missing here?

@tillahoffmann
Copy link
Contributor Author

The motivation of this PR is that networkx changes the default behavior of plotting with matplotlib. As a user, I would've expected the plotting function to do just one thing in the spirit of separation of concerns: plot the network without modifying the axes.

In other words, I would've expected the code that hides the labels do be its own piece of code, maybe a utility function. I introduced the keyword argument to maintain backwards compatibility.

Re-enabling the axes after using the networkx plotting function doesn't seem to be uncommon, e.g.,

@rossbar rossbar added the Visualization Related to graph visualization or layout label Nov 22, 2022
@dschult
Copy link
Member

dschult commented Nov 22, 2022

I'll take this as a request to change the default then. I don't want to get into the business of providing the options that matplotlib provides. Long long ago there was a version that kept the axis ticks on by default. But we changed it to what I think might be a better default. I think that the numbers on the axes are usually irrelevant and get in the way.

Perhaps we should put a note in the doc_string (or somewhere else better?) telling people how to do this? Or maybe StackOverFlow is enough? Thoughts?

@tillahoffmann
Copy link
Contributor Author

Yes, I think changing the default would be desirable. I almost always turn the ticks back on for development and only remove them for publication figures.

Another argument for changing the default is that plotting currently depends on the order of execution. E.g., I might set ticks or tick labels before plotting and find that they have disappeared. In contrast, if I set the x-limits or tick labels and plot another object (e.g., using plt.plot or plt.hist), they will remain unchanged. It surprised me that a plotting function would also change the parent axes properties.

Copy link
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

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

I'm -1 on changing the default, and usually I'm against expanding the already bloated visualization API but I think the argument to add a kwarg to control this behavior is compelling.

The matplotlib tick_params API is verbose enough that users are likely to have too look it up each time they want to modify it. Replacing this with a toggle makes sense. Unfortunately the toggle itself will have discoverability issues swimming in the sea of existing keyword arguments, but searching the nx_pylab docs with a ctrl+f "tick" is at least as discoverable as finding the tick_labels object in the matplotlib refguide. Ultimately I'm in favor of this proposal!

Copy link
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

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

I took the liberty of pushing up a bit more info in the parameter description in the docstring, but otherwise this LGTM. Thanks for the suggestion @tillahoffmann and the well-researched/tested proposal!

@dschult
Copy link
Member

dschult commented Mar 21, 2024

I can "justify" accepting this change along-side our general policy of not implementing matplotlib style features within our code kwargs as follows:

This hide_ticks kwarg makes our already existing non-default style choice for matplotlib optional. Our existing default behavior of hiding ticks was implemented after many years of showing ticks which was problematic -- users couldn't find how to turn them off. At that time, we debated whether it was worth turning off the ticks -- it is the better look for most pictures of networks. Turning them off is fairly involved and you need to know details about matplotlib to do it. But it goes against our preference for leaving style choices to the matplotlib interface. In the end we decided to implement this style choice even though users could make that choice via (somewhat involved) matplotlib commands.

This PR allows users to turn off that style choice. So I am supportive of this PR.

Thanks @rossbar for your work with this (including bringing it to the community meeting agenda). And Thanks @tillahoffmann for the PR (sorry this took so long! :)

@dschult dschult merged commit 0efae02 into networkx:main Mar 21, 2024
41 checks passed
@jarrodmillman jarrodmillman added this to the 3.3 milestone Mar 21, 2024
@tillahoffmann
Copy link
Contributor Author

Thanks for merging and the thorough review!

cvanelteren pushed a commit to cvanelteren/networkx that referenced this pull request Apr 22, 2024
* Add option to hide or show tick labels.

* Update parameter description in docstring.

---------

Co-authored-by: Ross Barnowski <rossbar@caltech.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: Enhancements Visualization Related to graph visualization or layout
Development

Successfully merging this pull request may close these issues.

None yet

4 participants