-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Closed
Labels
Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesNew feature
Description
I want to be able to set the xticks or yticks based on user input, but I can't seem to do this without invoking an if statement in order to use the default behaviour.
To get the default xticks for example, you can run:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0,1)
plt.plot(x, x**2)
plt.xticks()
plt.show()However, if I want a user-set variable to set the xticks, I have to do this:
import numpy as np
import matplotlib.pyplot as plt
user_option = None
x = np.linspace(0,1)
plt.plot(x, x**2)
if user_option == None:
plt.xticks()
else:
plt.xticks(user_option)
plt.show()Since the code plt.xticks(None) gives the following error:
Traceback (most recent call last):
File "tmp.py", line 9, in <module>
plt.xticks(None)
File "/home/vanwyk/py_envs/py3/lib/python3.4/site-packages/matplotlib/pyplot.py", line 1671, in xticks
locs = ax.set_xticks(args[0])
File "/home/vanwyk/py_envs/py3/lib/python3.4/site-packages/matplotlib/axes/_base.py", line 2850, in set_xticks
ret = self.xaxis.set_ticks(ticks, minor=minor)
File "/home/vanwyk/py_envs/py3/lib/python3.4/site-packages/matplotlib/axis.py", line 1595, in set_ticks
if len(ticks) > 1:
TypeError: object of type 'NoneType' has no len()Could the plt.xticks and plt.yticks functions allow the passing of None to retrieve default behaviour, or is there some way of getting the default ticks while still passing a variable?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesNew feature