Why does this plot fail when adding scatter but it works when removing it?












0















I am using the following to plot a x date and y decimal. It works great without the commented line (scatter), but if you uncomment it it shows all in one x axis



what am I missing?



thanks



import matplotlib.pyplot as plt
import datetime

fig = plt.figure(facecolor="#979899")
ax = plt.gca()
ax.set_facecolor("#d1d1d1")
plt.grid(True)
plt.title("This is a title",fontsize=16)

plt.xticks([datetime.date(2018,11,20),datetime.date(2018,11,21),datetime.date(2018,11,22)],["11/20","11/21","11/22"])
plt.yticks([0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0],["0.0","0.1","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9","1.0"])

x1 = [datetime.date(2018,11,20),datetime.date(2018,11,21),datetime.date(2018,11,22)]
y1 = [0.18,0.32,0.21]

for i,item in enumerate(y1):
xP = x1[i]
yP = y1[i]
plt.text(xP,yP,str(item)+"%",fontsize=11)

#plt.scatter(x1,y1)
plt.plot(x1,y1)
plt.show()









share|improve this question



























    0















    I am using the following to plot a x date and y decimal. It works great without the commented line (scatter), but if you uncomment it it shows all in one x axis



    what am I missing?



    thanks



    import matplotlib.pyplot as plt
    import datetime

    fig = plt.figure(facecolor="#979899")
    ax = plt.gca()
    ax.set_facecolor("#d1d1d1")
    plt.grid(True)
    plt.title("This is a title",fontsize=16)

    plt.xticks([datetime.date(2018,11,20),datetime.date(2018,11,21),datetime.date(2018,11,22)],["11/20","11/21","11/22"])
    plt.yticks([0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0],["0.0","0.1","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9","1.0"])

    x1 = [datetime.date(2018,11,20),datetime.date(2018,11,21),datetime.date(2018,11,22)]
    y1 = [0.18,0.32,0.21]

    for i,item in enumerate(y1):
    xP = x1[i]
    yP = y1[i]
    plt.text(xP,yP,str(item)+"%",fontsize=11)

    #plt.scatter(x1,y1)
    plt.plot(x1,y1)
    plt.show()









    share|improve this question

























      0












      0








      0








      I am using the following to plot a x date and y decimal. It works great without the commented line (scatter), but if you uncomment it it shows all in one x axis



      what am I missing?



      thanks



      import matplotlib.pyplot as plt
      import datetime

      fig = plt.figure(facecolor="#979899")
      ax = plt.gca()
      ax.set_facecolor("#d1d1d1")
      plt.grid(True)
      plt.title("This is a title",fontsize=16)

      plt.xticks([datetime.date(2018,11,20),datetime.date(2018,11,21),datetime.date(2018,11,22)],["11/20","11/21","11/22"])
      plt.yticks([0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0],["0.0","0.1","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9","1.0"])

      x1 = [datetime.date(2018,11,20),datetime.date(2018,11,21),datetime.date(2018,11,22)]
      y1 = [0.18,0.32,0.21]

      for i,item in enumerate(y1):
      xP = x1[i]
      yP = y1[i]
      plt.text(xP,yP,str(item)+"%",fontsize=11)

      #plt.scatter(x1,y1)
      plt.plot(x1,y1)
      plt.show()









      share|improve this question














      I am using the following to plot a x date and y decimal. It works great without the commented line (scatter), but if you uncomment it it shows all in one x axis



      what am I missing?



      thanks



      import matplotlib.pyplot as plt
      import datetime

      fig = plt.figure(facecolor="#979899")
      ax = plt.gca()
      ax.set_facecolor("#d1d1d1")
      plt.grid(True)
      plt.title("This is a title",fontsize=16)

      plt.xticks([datetime.date(2018,11,20),datetime.date(2018,11,21),datetime.date(2018,11,22)],["11/20","11/21","11/22"])
      plt.yticks([0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0],["0.0","0.1","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9","1.0"])

      x1 = [datetime.date(2018,11,20),datetime.date(2018,11,21),datetime.date(2018,11,22)]
      y1 = [0.18,0.32,0.21]

      for i,item in enumerate(y1):
      xP = x1[i]
      yP = y1[i]
      plt.text(xP,yP,str(item)+"%",fontsize=11)

      #plt.scatter(x1,y1)
      plt.plot(x1,y1)
      plt.show()






      python matplotlib






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 3:06









      RollRollRollRoll

      3,3981353113




      3,3981353113
























          2 Answers
          2






          active

          oldest

          votes


















          2














          The problem is the autoscaling of Collections. This is the underlying issue, which is long known, but hard to come by. There are certain cases, where autoscaling does not work reliably, when values are too close to each other. This is unfortunately often the case for dates.



          import matplotlib.pyplot as plt
          import datetime

          fig, ax = plt.subplots()

          x1 = [datetime.date(2018,11,20),datetime.date(2018,11,22)]
          y1 = [1,2]

          plt.scatter(x1,y1, s=50, color="red")
          plt.plot(x1,y1, marker="o", ms=3, zorder=3)

          plt.show()


          enter image description here



          You can however create a plot first. This will determine the autoscaling limits sufficiently. After that plot the scatter.



          import matplotlib.pyplot as plt
          import datetime

          fig, ax = plt.subplots()

          x1 = [datetime.date(2018,11,20),datetime.date(2018,11,22)]
          y1 = [1,2]

          plt.plot(x1,y1, marker="o", ms=3)
          plt.scatter(x1,y1, s=50, color="red")

          plt.show()


          enter image description here






          share|improve this answer


























          • that's a weird bug tks

            – RollRoll
            Nov 24 '18 at 17:51



















          1














          try setting the limits for both x and y axes:



          plt.scatter(x1,y1)
          plt.plot(x1,y1)
          plt.xlim(datetime.date(2018,11,20),datetime.date(2018,11,22))
          plt.ylim(0.1,0.4)
          plt.show()





          share|improve this answer























            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%2f53454831%2fwhy-does-this-plot-fail-when-adding-scatter-but-it-works-when-removing-it%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            The problem is the autoscaling of Collections. This is the underlying issue, which is long known, but hard to come by. There are certain cases, where autoscaling does not work reliably, when values are too close to each other. This is unfortunately often the case for dates.



            import matplotlib.pyplot as plt
            import datetime

            fig, ax = plt.subplots()

            x1 = [datetime.date(2018,11,20),datetime.date(2018,11,22)]
            y1 = [1,2]

            plt.scatter(x1,y1, s=50, color="red")
            plt.plot(x1,y1, marker="o", ms=3, zorder=3)

            plt.show()


            enter image description here



            You can however create a plot first. This will determine the autoscaling limits sufficiently. After that plot the scatter.



            import matplotlib.pyplot as plt
            import datetime

            fig, ax = plt.subplots()

            x1 = [datetime.date(2018,11,20),datetime.date(2018,11,22)]
            y1 = [1,2]

            plt.plot(x1,y1, marker="o", ms=3)
            plt.scatter(x1,y1, s=50, color="red")

            plt.show()


            enter image description here






            share|improve this answer


























            • that's a weird bug tks

              – RollRoll
              Nov 24 '18 at 17:51
















            2














            The problem is the autoscaling of Collections. This is the underlying issue, which is long known, but hard to come by. There are certain cases, where autoscaling does not work reliably, when values are too close to each other. This is unfortunately often the case for dates.



            import matplotlib.pyplot as plt
            import datetime

            fig, ax = plt.subplots()

            x1 = [datetime.date(2018,11,20),datetime.date(2018,11,22)]
            y1 = [1,2]

            plt.scatter(x1,y1, s=50, color="red")
            plt.plot(x1,y1, marker="o", ms=3, zorder=3)

            plt.show()


            enter image description here



            You can however create a plot first. This will determine the autoscaling limits sufficiently. After that plot the scatter.



            import matplotlib.pyplot as plt
            import datetime

            fig, ax = plt.subplots()

            x1 = [datetime.date(2018,11,20),datetime.date(2018,11,22)]
            y1 = [1,2]

            plt.plot(x1,y1, marker="o", ms=3)
            plt.scatter(x1,y1, s=50, color="red")

            plt.show()


            enter image description here






            share|improve this answer


























            • that's a weird bug tks

              – RollRoll
              Nov 24 '18 at 17:51














            2












            2








            2







            The problem is the autoscaling of Collections. This is the underlying issue, which is long known, but hard to come by. There are certain cases, where autoscaling does not work reliably, when values are too close to each other. This is unfortunately often the case for dates.



            import matplotlib.pyplot as plt
            import datetime

            fig, ax = plt.subplots()

            x1 = [datetime.date(2018,11,20),datetime.date(2018,11,22)]
            y1 = [1,2]

            plt.scatter(x1,y1, s=50, color="red")
            plt.plot(x1,y1, marker="o", ms=3, zorder=3)

            plt.show()


            enter image description here



            You can however create a plot first. This will determine the autoscaling limits sufficiently. After that plot the scatter.



            import matplotlib.pyplot as plt
            import datetime

            fig, ax = plt.subplots()

            x1 = [datetime.date(2018,11,20),datetime.date(2018,11,22)]
            y1 = [1,2]

            plt.plot(x1,y1, marker="o", ms=3)
            plt.scatter(x1,y1, s=50, color="red")

            plt.show()


            enter image description here






            share|improve this answer















            The problem is the autoscaling of Collections. This is the underlying issue, which is long known, but hard to come by. There are certain cases, where autoscaling does not work reliably, when values are too close to each other. This is unfortunately often the case for dates.



            import matplotlib.pyplot as plt
            import datetime

            fig, ax = plt.subplots()

            x1 = [datetime.date(2018,11,20),datetime.date(2018,11,22)]
            y1 = [1,2]

            plt.scatter(x1,y1, s=50, color="red")
            plt.plot(x1,y1, marker="o", ms=3, zorder=3)

            plt.show()


            enter image description here



            You can however create a plot first. This will determine the autoscaling limits sufficiently. After that plot the scatter.



            import matplotlib.pyplot as plt
            import datetime

            fig, ax = plt.subplots()

            x1 = [datetime.date(2018,11,20),datetime.date(2018,11,22)]
            y1 = [1,2]

            plt.plot(x1,y1, marker="o", ms=3)
            plt.scatter(x1,y1, s=50, color="red")

            plt.show()


            enter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 29 '18 at 13:40

























            answered Nov 24 '18 at 3:23









            ImportanceOfBeingErnestImportanceOfBeingErnest

            132k13144219




            132k13144219













            • that's a weird bug tks

              – RollRoll
              Nov 24 '18 at 17:51



















            • that's a weird bug tks

              – RollRoll
              Nov 24 '18 at 17:51

















            that's a weird bug tks

            – RollRoll
            Nov 24 '18 at 17:51





            that's a weird bug tks

            – RollRoll
            Nov 24 '18 at 17:51













            1














            try setting the limits for both x and y axes:



            plt.scatter(x1,y1)
            plt.plot(x1,y1)
            plt.xlim(datetime.date(2018,11,20),datetime.date(2018,11,22))
            plt.ylim(0.1,0.4)
            plt.show()





            share|improve this answer




























              1














              try setting the limits for both x and y axes:



              plt.scatter(x1,y1)
              plt.plot(x1,y1)
              plt.xlim(datetime.date(2018,11,20),datetime.date(2018,11,22))
              plt.ylim(0.1,0.4)
              plt.show()





              share|improve this answer


























                1












                1








                1







                try setting the limits for both x and y axes:



                plt.scatter(x1,y1)
                plt.plot(x1,y1)
                plt.xlim(datetime.date(2018,11,20),datetime.date(2018,11,22))
                plt.ylim(0.1,0.4)
                plt.show()





                share|improve this answer













                try setting the limits for both x and y axes:



                plt.scatter(x1,y1)
                plt.plot(x1,y1)
                plt.xlim(datetime.date(2018,11,20),datetime.date(2018,11,22))
                plt.ylim(0.1,0.4)
                plt.show()






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 24 '18 at 3:13









                tengteng

                842721




                842721






























                    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%2f53454831%2fwhy-does-this-plot-fail-when-adding-scatter-but-it-works-when-removing-it%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

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    TypeError: fit_transform() missing 1 required positional argument: 'X'