Using matplotlib
in Python, how could I pass two keywords to pyplot.axis()
? Something like: pyplot.axis('tight', 'off')
Looking around the help and the source, I don't think you can do that.
From help(pyplot.axis)
:
axis(*v, **kwargs)
Convenience method to get or set axis properties.
Convenience method. This, to me, already suggests that we shouldn't have too high expectations regarding the method. The rest of the help also seems to suggest that only a single string argument can be passed.
So let's look at the source. For me, pyplot.axis
is in /usr/local/lib/python3.4/dist-packages/matplotlib/pyplot.py
. On line 1443 begins the definition of axis
, and without further ado it simply passes the problem to the underlying axes object:
return gca().axis(*v, **kwargs)
So we need the axis()
method of an Axes
object usually. This class is defined in /usr/local/lib/python3.4/dist-packages/matplotlib/axes/_axes.py
, but it turns out that it doesn't have an axis()
method defined. So, it's inherited from _AxesBase
instead. This resides in /usr/local/lib/python3.4/dist-packages/matplotlib/axes/_base.py
.
Now, _AxesBase
finally implements axis()
. The beginning:
def axis(self, *v, **kwargs):
"""Set axis properties.
Valid signatures::
xmin, xmax, ymin, ymax = axis()
xmin, xmax, ymin, ymax = axis(list_arg)
xmin, xmax, ymin, ymax = axis(string_arg)
xmin, xmax, ymin, ymax = axis(**kwargs)
...
Well, this docstring doesn't look good, again it suggests that only a single string argument can be provided. Looking at the implementation supports this impression. The string-based inputs are handled in a block beginning like this:
if len(v) == 1 and is_string_like(v[0]):
s = v[0].lower()
if s == 'on':
self.set_axis_on()
elif s == 'off':
self.set_axis_off()
elif s in ('equal', 'tight', 'scaled', 'normal',
'auto', 'image', 'square'):
...
These strings don't appear anywhere in the method outside this if
block, but the condition of the if
clearly assumes scalar input, or in the worst case a single-element iterable. This means that you cannot pass multiple strings at the same time to axis
.
Note that you can look at what each option does, and manually use them if you wish. Of course the result should be equivalent to you calling pyplot.axis
multiple times, but the order of the commands will be well-defined (which might matter), and you can get rid of some overhead in the function calls.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments