Using multiple keywords in pyplot.axis in matplotlib

graffaner

Using matplotlib in Python, how could I pass two keywords to pyplot.axis()? Something like: pyplot.axis('tight', 'off')

Andras Deak

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using passed axis objects in a matplotlib.pyplot figure?

From Dev

Multiple y axis using matplotlib not working

From Dev

Pyplot: using percentage on x axis

From Dev

Axis error in matplotlib.pyplot.streamplot

From Dev

Matplotlib/Pyplot shared axis for odd number of subplots

From Dev

Set axis origin using PyPlot plot in Julia

From Dev

Plot multiple curves with matplotlib.pyplot.fill

From Dev

Having Multiple Lines in a Plot: matplotlib.pyplot

From Dev

matplotlib.pyplot plot x-axis ticks in equal range

From Dev

Changing the count of numbers of the y-axis (Python, matplotlib.pyplot)

From Dev

Matplotlib pyplot set axis limits after rescaling equal

From Dev

Recognizing multiple keywords using PocketSphinx

From Dev

Split using multiple keywords as demiliters

From Dev

No visible text() when using matplotlib.pyplot

From Dev

Visualize MNIST dataset using OpenCV or Matplotlib/Pyplot

From Dev

Visualize MNIST dataset using OpenCV or Matplotlib/Pyplot

From Dev

No visible text() when using matplotlib.pyplot

From Dev

Split using multiple keywords using regex

From Dev

matplotlib.pyplot.plotfile() - How to plot multiple graphs into same figure?

From Dev

matplotlib (python) - create single custom legend for multiple plots WITHOUT pyplot

From Dev

Plot multiple data using for loop, pyplot and genfromtxt

From Dev

Chrome extension using multiple omnibox keywords

From Dev

Using multiple keywords in xattr via _kMDItemUserTags or kMDItemOMUserTags

From Dev

search through a database using multiple keywords in php

From Dev

Using excel search function while there are multiple keywords

From Dev

AngularJS search multiple keywords using one field

From Dev

JavaScript – Issue using multiple keywords with RegExp

From Dev

Matching multiple keywords using contains() in jQuery

From Dev

Format of datetime in pyplot axis

Related Related

  1. 1

    Using passed axis objects in a matplotlib.pyplot figure?

  2. 2

    Multiple y axis using matplotlib not working

  3. 3

    Pyplot: using percentage on x axis

  4. 4

    Axis error in matplotlib.pyplot.streamplot

  5. 5

    Matplotlib/Pyplot shared axis for odd number of subplots

  6. 6

    Set axis origin using PyPlot plot in Julia

  7. 7

    Plot multiple curves with matplotlib.pyplot.fill

  8. 8

    Having Multiple Lines in a Plot: matplotlib.pyplot

  9. 9

    matplotlib.pyplot plot x-axis ticks in equal range

  10. 10

    Changing the count of numbers of the y-axis (Python, matplotlib.pyplot)

  11. 11

    Matplotlib pyplot set axis limits after rescaling equal

  12. 12

    Recognizing multiple keywords using PocketSphinx

  13. 13

    Split using multiple keywords as demiliters

  14. 14

    No visible text() when using matplotlib.pyplot

  15. 15

    Visualize MNIST dataset using OpenCV or Matplotlib/Pyplot

  16. 16

    Visualize MNIST dataset using OpenCV or Matplotlib/Pyplot

  17. 17

    No visible text() when using matplotlib.pyplot

  18. 18

    Split using multiple keywords using regex

  19. 19

    matplotlib.pyplot.plotfile() - How to plot multiple graphs into same figure?

  20. 20

    matplotlib (python) - create single custom legend for multiple plots WITHOUT pyplot

  21. 21

    Plot multiple data using for loop, pyplot and genfromtxt

  22. 22

    Chrome extension using multiple omnibox keywords

  23. 23

    Using multiple keywords in xattr via _kMDItemUserTags or kMDItemOMUserTags

  24. 24

    search through a database using multiple keywords in php

  25. 25

    Using excel search function while there are multiple keywords

  26. 26

    AngularJS search multiple keywords using one field

  27. 27

    JavaScript – Issue using multiple keywords with RegExp

  28. 28

    Matching multiple keywords using contains() in jQuery

  29. 29

    Format of datetime in pyplot axis

HotTag

Archive