How to label Positive and negative x-axis using set_xlabel?












0















In the following code I have created 4 axis. Positive and negative x and y axis. I want to label positive x-axis as c1,negative x-axis as c2, positive y-axis as h1 and negative y-axis as h2. If I use ax.set_xlabel it will label whole x-axis. But I want to assign different labels to positive and negative x-axis. How can I do that?



`fig = plt.figure()
ax= fig.add_subplot(111)
x = [0.1,0.2,-0.2,0.3]
y=[0.3,-0.2,0.4,0.3]
ax.scatter(x,y)
ax.set_xlim([-0.5, 0.5])
ax.set_ylim([-0.5, 0.5])


ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.spines['bottom'].set_position('zero')`









share|improve this question



























    0















    In the following code I have created 4 axis. Positive and negative x and y axis. I want to label positive x-axis as c1,negative x-axis as c2, positive y-axis as h1 and negative y-axis as h2. If I use ax.set_xlabel it will label whole x-axis. But I want to assign different labels to positive and negative x-axis. How can I do that?



    `fig = plt.figure()
    ax= fig.add_subplot(111)
    x = [0.1,0.2,-0.2,0.3]
    y=[0.3,-0.2,0.4,0.3]
    ax.scatter(x,y)
    ax.set_xlim([-0.5, 0.5])
    ax.set_ylim([-0.5, 0.5])


    ax.spines['left'].set_position('zero')
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    ax.spines['bottom'].set_position('zero')`









    share|improve this question

























      0












      0








      0








      In the following code I have created 4 axis. Positive and negative x and y axis. I want to label positive x-axis as c1,negative x-axis as c2, positive y-axis as h1 and negative y-axis as h2. If I use ax.set_xlabel it will label whole x-axis. But I want to assign different labels to positive and negative x-axis. How can I do that?



      `fig = plt.figure()
      ax= fig.add_subplot(111)
      x = [0.1,0.2,-0.2,0.3]
      y=[0.3,-0.2,0.4,0.3]
      ax.scatter(x,y)
      ax.set_xlim([-0.5, 0.5])
      ax.set_ylim([-0.5, 0.5])


      ax.spines['left'].set_position('zero')
      ax.spines['right'].set_color('none')
      ax.spines['top'].set_color('none')
      ax.spines['bottom'].set_position('zero')`









      share|improve this question














      In the following code I have created 4 axis. Positive and negative x and y axis. I want to label positive x-axis as c1,negative x-axis as c2, positive y-axis as h1 and negative y-axis as h2. If I use ax.set_xlabel it will label whole x-axis. But I want to assign different labels to positive and negative x-axis. How can I do that?



      `fig = plt.figure()
      ax= fig.add_subplot(111)
      x = [0.1,0.2,-0.2,0.3]
      y=[0.3,-0.2,0.4,0.3]
      ax.scatter(x,y)
      ax.set_xlim([-0.5, 0.5])
      ax.set_ylim([-0.5, 0.5])


      ax.spines['left'].set_position('zero')
      ax.spines['right'].set_color('none')
      ax.spines['top'].set_color('none')
      ax.spines['bottom'].set_position('zero')`






      python matplotlib






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 1:33









      R.joeR.joe

      46




      46
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You can use matplotlib.pyplot.text(x, y, s, fontdict=None, withdash=False, **kwargs) to write text at a specified location on your graph. x and y correspond to the location of the string, s is the string.






          share|improve this answer
























          • In ax.text(0.21,-0.1,h1) labels positive x axis. What values should I assign to go on negative x-axis?

            – R.joe
            Nov 16 '18 at 2:12











          • That is a symmetry around the Y axis, so you need to change the sign of x. Therefore, ax.text(-0.21, 0.1, '').

            – Patol75
            Nov 16 '18 at 2:14













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330221%2fhow-to-label-positive-and-negative-x-axis-using-set-xlabel%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You can use matplotlib.pyplot.text(x, y, s, fontdict=None, withdash=False, **kwargs) to write text at a specified location on your graph. x and y correspond to the location of the string, s is the string.






          share|improve this answer
























          • In ax.text(0.21,-0.1,h1) labels positive x axis. What values should I assign to go on negative x-axis?

            – R.joe
            Nov 16 '18 at 2:12











          • That is a symmetry around the Y axis, so you need to change the sign of x. Therefore, ax.text(-0.21, 0.1, '').

            – Patol75
            Nov 16 '18 at 2:14


















          0














          You can use matplotlib.pyplot.text(x, y, s, fontdict=None, withdash=False, **kwargs) to write text at a specified location on your graph. x and y correspond to the location of the string, s is the string.






          share|improve this answer
























          • In ax.text(0.21,-0.1,h1) labels positive x axis. What values should I assign to go on negative x-axis?

            – R.joe
            Nov 16 '18 at 2:12











          • That is a symmetry around the Y axis, so you need to change the sign of x. Therefore, ax.text(-0.21, 0.1, '').

            – Patol75
            Nov 16 '18 at 2:14
















          0












          0








          0







          You can use matplotlib.pyplot.text(x, y, s, fontdict=None, withdash=False, **kwargs) to write text at a specified location on your graph. x and y correspond to the location of the string, s is the string.






          share|improve this answer













          You can use matplotlib.pyplot.text(x, y, s, fontdict=None, withdash=False, **kwargs) to write text at a specified location on your graph. x and y correspond to the location of the string, s is the string.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 2:00









          Patol75Patol75

          6236




          6236













          • In ax.text(0.21,-0.1,h1) labels positive x axis. What values should I assign to go on negative x-axis?

            – R.joe
            Nov 16 '18 at 2:12











          • That is a symmetry around the Y axis, so you need to change the sign of x. Therefore, ax.text(-0.21, 0.1, '').

            – Patol75
            Nov 16 '18 at 2:14





















          • In ax.text(0.21,-0.1,h1) labels positive x axis. What values should I assign to go on negative x-axis?

            – R.joe
            Nov 16 '18 at 2:12











          • That is a symmetry around the Y axis, so you need to change the sign of x. Therefore, ax.text(-0.21, 0.1, '').

            – Patol75
            Nov 16 '18 at 2:14



















          In ax.text(0.21,-0.1,h1) labels positive x axis. What values should I assign to go on negative x-axis?

          – R.joe
          Nov 16 '18 at 2:12





          In ax.text(0.21,-0.1,h1) labels positive x axis. What values should I assign to go on negative x-axis?

          – R.joe
          Nov 16 '18 at 2:12













          That is a symmetry around the Y axis, so you need to change the sign of x. Therefore, ax.text(-0.21, 0.1, '').

          – Patol75
          Nov 16 '18 at 2:14







          That is a symmetry around the Y axis, so you need to change the sign of x. Therefore, ax.text(-0.21, 0.1, '').

          – Patol75
          Nov 16 '18 at 2:14






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330221%2fhow-to-label-positive-and-negative-x-axis-using-set-xlabel%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma