Matplotlib axes label

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Henry

    #1

    Matplotlib axes label

    I've been asking this question at the matplotlib user list and never
    gotten an answer. I am hoping that there are matplotlib users here
    that can help.

    My problem with matplotlib's way of handling axes label is illustrated
    by this example:



    Notice that the y-axis goes from (-1.1, 1.1) but the first label is at
    -1.0. I really don't like that because when I read values off the
    graph, I have to keep reminding myself that the origin is at -1.1.
    This may seem trivial but if you have to think, walk, chew gums at the
    same time you're reading the graph, it gets annoying - particularly if
    you have to read lots of these graphs.

    Is there a way to force the label to start at -1.1 instead of -1.0?

    Thanks,

  • attn.steven.kuo@gmail.com

    #2
    Re: Matplotlib axes label

    On Mar 1, 3:10 pm, "John Henry" <john106he...@h otmail.comwrote :
    I've been asking this question at the matplotlib user list and never
    gotten an answer. I am hoping that there are matplotlib users here
    that can help.
    >
    My problem with matplotlib's way of handling axes label is illustrated
    by this example:
    >

    >
    Notice that the y-axis goes from (-1.1, 1.1) but the first label is at
    -1.0.
    (snipped)
    Is there a way to force the label to start at -1.1 instead of -1.0?
    >
    Thanks,

    You can try adjusting the labels and ticks
    using matplotlib.tick er.

    To the example you cited, one can add

    from matplotlib.tick er import MultipleLocator , FormatStrFormat ter

    # ...

    minorLocator = MultipleLocator (0.1)
    minorFormattor = FormatStrFormat ter('%0.1f')
    ax.yaxis.set_mi nor_locator(min orLocator)
    ax.yaxis.set_mi nor_formatter(m inorFormattor)

    show()

    --
    Hope this helps,
    Steven

    Comment

    • John Henry

      #3
      Re: Matplotlib axes label

      On Mar 1, 9:53 pm, attn.steven.... @gmail.com wrote:
      On Mar 1, 3:10 pm, "John Henry" <john106he...@h otmail.comwrote :
      >
      I've been asking this question at the matplotlib user list and never
      gotten an answer. I am hoping that there are matplotlib users here
      that can help.
      >
      My problem with matplotlib's way of handling axes label is illustrated
      by this example:
      >>
      Notice that the y-axis goes from (-1.1, 1.1) but the first label is at
      -1.0.
      >
      (snipped)
      >
      Is there a way to force the label to start at -1.1 instead of -1.0?
      >
      Thanks,
      >
      You can try adjusting the labels and ticks
      using matplotlib.tick er.
      >
      To the example you cited, one can add
      >
      from matplotlib.tick er import MultipleLocator , FormatStrFormat ter
      >
      # ...
      >
      minorLocator = MultipleLocator (0.1)
      minorFormattor = FormatStrFormat ter('%0.1f')
      ax.yaxis.set_mi nor_locator(min orLocator)
      ax.yaxis.set_mi nor_formatter(m inorFormattor)
      >
      show()
      >
      --
      Hope this helps,
      Steven

      Thank you for the response. Yes, adding those lines did work.

      But what exactly is going on here? Why would adding these two lines
      works?

      Thanks,

      Comment

      • John Henry

        #4
        Re: Matplotlib axes label

        On Mar 1, 10:07 pm, "John Henry" <john106he...@h otmail.comwrote :
        On Mar 1, 9:53 pm, attn.steven.... @gmail.com wrote:
        >
        >
        >
        On Mar 1, 3:10 pm, "John Henry" <john106he...@h otmail.comwrote :
        >
        I've been asking this question at the matplotlib user list and never
        gotten an answer. I am hoping that there are matplotlib users here
        that can help.
        >
        My problem with matplotlib's way of handling axes label is illustrated
        by this example:
        >>
        Notice that the y-axis goes from (-1.1, 1.1) but the first label is at
        -1.0.
        >
        (snipped)
        >
        Is there a way to force the label to start at -1.1 instead of -1.0?
        >
        Thanks,
        >
        You can try adjusting the labels and ticks
        using matplotlib.tick er.
        >
        To the example you cited, one can add
        >
        from matplotlib.tick er import MultipleLocator , FormatStrFormat ter
        >
        # ...
        >
        minorLocator = MultipleLocator (0.1)
        minorFormattor = FormatStrFormat ter('%0.1f')
        ax.yaxis.set_mi nor_locator(min orLocator)
        ax.yaxis.set_mi nor_formatter(m inorFormattor)
        >
        show()
        >
        --
        Hope this helps,
        Steven
        >
        Thank you for the response. Yes, adding those lines did work.
        >
        But what exactly is going on here? Why would adding these two lines
        works?
        >
        Thanks,

        Okay, I played with the ticker formater and locator routines.
        Unfortunately, it doesn't help. The locator sets the major value and
        the formatter determines how the axes label is formatted. It doesn't
        gurantee that the first label starts at the origin. Half of my plots
        works, and half of them doesn't.

        Comment

        • attn.steven.kuo@gmail.com

          #5
          Re: Matplotlib axes label

          On Mar 2, 7:02 am, "John Henry" <john106he...@h otmail.comwrote :
          On Mar 1, 10:07 pm, "John Henry" <john106he...@h otmail.comwrote :
          >
          >
          >
          On Mar 1, 9:53 pm, attn.steven.... @gmail.com wrote:
          >
          (snipped)
          You can try adjusting the labels and ticks
          using matplotlib.tick er.
          >
          To the example you cited, one can add
          >
          from matplotlib.tick er import MultipleLocator , FormatStrFormat ter
          >
          # ...
          >
          minorLocator = MultipleLocator (0.1)
          minorFormattor = FormatStrFormat ter('%0.1f')
          ax.yaxis.set_mi nor_locator(min orLocator)
          ax.yaxis.set_mi nor_formatter(m inorFormattor)
          >
          show()
          >
          >
          Thank you for the response. Yes, adding those lines did work.
          >
          But what exactly is going on here? Why would adding these two lines
          works?
          >
          Thanks,
          >
          Okay, I played with the ticker formater and locator routines.
          Unfortunately, it doesn't help. The locator sets the major value and
          the formatter determines how the axes label is formatted. It doesn't
          gurantee that the first label starts at the origin. Half of my plots
          works, and half of them doesn't.




          As default, matplotlib places labels and tick marks
          at major ticks. Minor ticks are invisible as
          a default.

          The lines that I added turned on *minor*
          ticks and their labels; I set them to appear
          at integer multiples of 0.1 and I
          formatted them as floating point numbers.

          There's nothing to prevent you from
          having minor ticks appear at intervals
          that exceed those of major ticks. E.g.,

          minorLocator = MultipleLocator (1.1)

          # etc.

          --
          Hope this helps,
          Steven

          Comment

          • John Henry

            #6
            Re: Matplotlib axes label

            On Mar 2, 7:22 am, attn.steven.... @gmail.com wrote:
            On Mar 2, 7:02 am, "John Henry" <john106he...@h otmail.comwrote :
            >
            On Mar 1, 10:07 pm, "John Henry" <john106he...@h otmail.comwrote :
            >
            On Mar 1, 9:53 pm, attn.steven.... @gmail.com wrote:
            >
            (snipped)
            >
            >
            >
            You can try adjusting the labels and ticks
            using matplotlib.tick er.
            >
            To the example you cited, one can add
            >
            from matplotlib.tick er import MultipleLocator , FormatStrFormat ter
            >
            # ...
            >
            minorLocator = MultipleLocator (0.1)
            minorFormattor = FormatStrFormat ter('%0.1f')
            ax.yaxis.set_mi nor_locator(min orLocator)
            ax.yaxis.set_mi nor_formatter(m inorFormattor)
            >
            show()
            >
            Thank you for the response. Yes, adding those lines did work.
            >
            But what exactly is going on here? Why would adding these two lines
            works?
            >
            Thanks,
            >
            Okay, I played with the ticker formater and locator routines.
            Unfortunately, it doesn't help. The locator sets the major value and
            the formatter determines how the axes label is formatted. It doesn't
            gurantee that the first label starts at the origin. Half of my plots
            works, and half of them doesn't.
            >
            As default, matplotlib places labels and tick marks
            at major ticks. Minor ticks are invisible as
            a default.
            >
            The lines that I added turned on *minor*
            ticks and their labels; I set them to appear
            at integer multiples of 0.1 and I
            formatted them as floating point numbers.
            >
            There's nothing to prevent you from
            having minor ticks appear at intervals
            that exceed those of major ticks. E.g.,
            >
            minorLocator = MultipleLocator (1.1)
            >
            # etc.
            >
            --
            Hope this helps,
            Steven

            Thanks,

            Comment

            Working...