Stripplot and lineplot weird result












0















When I use lineplot or stripplot it works well. But using both the median is shifted; I don't understand why! Thank you for your help.



sns.lineplot(x='quality', y='alcohol', data=df, estimator=np.median, err_style=None)
sns.stripplot(x='quality', y='alcohol', data=df, jitter=True, color='red', alpha=0.2, edgecolor='none')


stripplot



lineplot+stripplot



lineplot










share|improve this question





























    0















    When I use lineplot or stripplot it works well. But using both the median is shifted; I don't understand why! Thank you for your help.



    sns.lineplot(x='quality', y='alcohol', data=df, estimator=np.median, err_style=None)
    sns.stripplot(x='quality', y='alcohol', data=df, jitter=True, color='red', alpha=0.2, edgecolor='none')


    stripplot



    lineplot+stripplot



    lineplot










    share|improve this question



























      0












      0








      0








      When I use lineplot or stripplot it works well. But using both the median is shifted; I don't understand why! Thank you for your help.



      sns.lineplot(x='quality', y='alcohol', data=df, estimator=np.median, err_style=None)
      sns.stripplot(x='quality', y='alcohol', data=df, jitter=True, color='red', alpha=0.2, edgecolor='none')


      stripplot



      lineplot+stripplot



      lineplot










      share|improve this question
















      When I use lineplot or stripplot it works well. But using both the median is shifted; I don't understand why! Thank you for your help.



      sns.lineplot(x='quality', y='alcohol', data=df, estimator=np.median, err_style=None)
      sns.stripplot(x='quality', y='alcohol', data=df, jitter=True, color='red', alpha=0.2, edgecolor='none')


      stripplot



      lineplot+stripplot



      lineplot







      python seaborn






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 1 at 13:23









      Scott Boston

      56.1k73157




      56.1k73157










      asked Dec 31 '18 at 10:55









      hgangerhganger

      143




      143
























          1 Answer
          1






          active

          oldest

          votes


















          0














          What is happening here is that your first plot is creating an x axis with 0 to n range, and relabeling those x tick with a list of integers from 3 to n, then when the second chart or the stripplot plots on top of this x axis it is using the original number therefore xtick 3 for this new chart starts on labelled xtick 6. Hence the offset.



          One way to do correct this is to create a xaxis with a predefined range and then plot both charts on this predefined scale, see example below:



          import seaborn as sns
          import matplotlib.pyplot as plt
          x = [3,4,5,6,7,8]
          y = [10, 12, 15, 18, 19, 26]

          #First axes creates the error in graphing
          fig, ax = plt.subplots(1,2)
          sns.lineplot(x=x,y=y, ax=ax[0])
          sns.stripplot(x=x, y=y, ax=ax[0])

          #Second axes shows correction
          xplot = range(len(x))
          sns.lineplot(x=xplot,y=y, ax=ax[1])
          sns.stripplot(x, y=y, ax=ax[1])


          Output:



          enter image description here






          share|improve this answer
























          • Thank you. However I don't understand how to apply it. I've a file with 4898 rows with 7 qualities and lineplot compute the median value (of alcohol variable) for each quality.

            – hganger
            Jan 1 at 10:17








          • 1





            Finally, I did it thanks to your post and the offset idea. labels, uniques = pd.factorize(df['quality'], sort = True) sns.lineplot(x=labels, y=df['alcohol'], estimator=np.median, err_style=None, color='black') sns.stripplot(x='quality', y='alcohol', data=df, jitter=True, color='red', alpha=0.2, edgecolor='none')

            – hganger
            Jan 1 at 10:35













          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%2f53986627%2fstripplot-and-lineplot-weird-result%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














          What is happening here is that your first plot is creating an x axis with 0 to n range, and relabeling those x tick with a list of integers from 3 to n, then when the second chart or the stripplot plots on top of this x axis it is using the original number therefore xtick 3 for this new chart starts on labelled xtick 6. Hence the offset.



          One way to do correct this is to create a xaxis with a predefined range and then plot both charts on this predefined scale, see example below:



          import seaborn as sns
          import matplotlib.pyplot as plt
          x = [3,4,5,6,7,8]
          y = [10, 12, 15, 18, 19, 26]

          #First axes creates the error in graphing
          fig, ax = plt.subplots(1,2)
          sns.lineplot(x=x,y=y, ax=ax[0])
          sns.stripplot(x=x, y=y, ax=ax[0])

          #Second axes shows correction
          xplot = range(len(x))
          sns.lineplot(x=xplot,y=y, ax=ax[1])
          sns.stripplot(x, y=y, ax=ax[1])


          Output:



          enter image description here






          share|improve this answer
























          • Thank you. However I don't understand how to apply it. I've a file with 4898 rows with 7 qualities and lineplot compute the median value (of alcohol variable) for each quality.

            – hganger
            Jan 1 at 10:17








          • 1





            Finally, I did it thanks to your post and the offset idea. labels, uniques = pd.factorize(df['quality'], sort = True) sns.lineplot(x=labels, y=df['alcohol'], estimator=np.median, err_style=None, color='black') sns.stripplot(x='quality', y='alcohol', data=df, jitter=True, color='red', alpha=0.2, edgecolor='none')

            – hganger
            Jan 1 at 10:35


















          0














          What is happening here is that your first plot is creating an x axis with 0 to n range, and relabeling those x tick with a list of integers from 3 to n, then when the second chart or the stripplot plots on top of this x axis it is using the original number therefore xtick 3 for this new chart starts on labelled xtick 6. Hence the offset.



          One way to do correct this is to create a xaxis with a predefined range and then plot both charts on this predefined scale, see example below:



          import seaborn as sns
          import matplotlib.pyplot as plt
          x = [3,4,5,6,7,8]
          y = [10, 12, 15, 18, 19, 26]

          #First axes creates the error in graphing
          fig, ax = plt.subplots(1,2)
          sns.lineplot(x=x,y=y, ax=ax[0])
          sns.stripplot(x=x, y=y, ax=ax[0])

          #Second axes shows correction
          xplot = range(len(x))
          sns.lineplot(x=xplot,y=y, ax=ax[1])
          sns.stripplot(x, y=y, ax=ax[1])


          Output:



          enter image description here






          share|improve this answer
























          • Thank you. However I don't understand how to apply it. I've a file with 4898 rows with 7 qualities and lineplot compute the median value (of alcohol variable) for each quality.

            – hganger
            Jan 1 at 10:17








          • 1





            Finally, I did it thanks to your post and the offset idea. labels, uniques = pd.factorize(df['quality'], sort = True) sns.lineplot(x=labels, y=df['alcohol'], estimator=np.median, err_style=None, color='black') sns.stripplot(x='quality', y='alcohol', data=df, jitter=True, color='red', alpha=0.2, edgecolor='none')

            – hganger
            Jan 1 at 10:35
















          0












          0








          0







          What is happening here is that your first plot is creating an x axis with 0 to n range, and relabeling those x tick with a list of integers from 3 to n, then when the second chart or the stripplot plots on top of this x axis it is using the original number therefore xtick 3 for this new chart starts on labelled xtick 6. Hence the offset.



          One way to do correct this is to create a xaxis with a predefined range and then plot both charts on this predefined scale, see example below:



          import seaborn as sns
          import matplotlib.pyplot as plt
          x = [3,4,5,6,7,8]
          y = [10, 12, 15, 18, 19, 26]

          #First axes creates the error in graphing
          fig, ax = plt.subplots(1,2)
          sns.lineplot(x=x,y=y, ax=ax[0])
          sns.stripplot(x=x, y=y, ax=ax[0])

          #Second axes shows correction
          xplot = range(len(x))
          sns.lineplot(x=xplot,y=y, ax=ax[1])
          sns.stripplot(x, y=y, ax=ax[1])


          Output:



          enter image description here






          share|improve this answer













          What is happening here is that your first plot is creating an x axis with 0 to n range, and relabeling those x tick with a list of integers from 3 to n, then when the second chart or the stripplot plots on top of this x axis it is using the original number therefore xtick 3 for this new chart starts on labelled xtick 6. Hence the offset.



          One way to do correct this is to create a xaxis with a predefined range and then plot both charts on this predefined scale, see example below:



          import seaborn as sns
          import matplotlib.pyplot as plt
          x = [3,4,5,6,7,8]
          y = [10, 12, 15, 18, 19, 26]

          #First axes creates the error in graphing
          fig, ax = plt.subplots(1,2)
          sns.lineplot(x=x,y=y, ax=ax[0])
          sns.stripplot(x=x, y=y, ax=ax[0])

          #Second axes shows correction
          xplot = range(len(x))
          sns.lineplot(x=xplot,y=y, ax=ax[1])
          sns.stripplot(x, y=y, ax=ax[1])


          Output:



          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 1 at 4:53









          Scott BostonScott Boston

          56.1k73157




          56.1k73157













          • Thank you. However I don't understand how to apply it. I've a file with 4898 rows with 7 qualities and lineplot compute the median value (of alcohol variable) for each quality.

            – hganger
            Jan 1 at 10:17








          • 1





            Finally, I did it thanks to your post and the offset idea. labels, uniques = pd.factorize(df['quality'], sort = True) sns.lineplot(x=labels, y=df['alcohol'], estimator=np.median, err_style=None, color='black') sns.stripplot(x='quality', y='alcohol', data=df, jitter=True, color='red', alpha=0.2, edgecolor='none')

            – hganger
            Jan 1 at 10:35





















          • Thank you. However I don't understand how to apply it. I've a file with 4898 rows with 7 qualities and lineplot compute the median value (of alcohol variable) for each quality.

            – hganger
            Jan 1 at 10:17








          • 1





            Finally, I did it thanks to your post and the offset idea. labels, uniques = pd.factorize(df['quality'], sort = True) sns.lineplot(x=labels, y=df['alcohol'], estimator=np.median, err_style=None, color='black') sns.stripplot(x='quality', y='alcohol', data=df, jitter=True, color='red', alpha=0.2, edgecolor='none')

            – hganger
            Jan 1 at 10:35



















          Thank you. However I don't understand how to apply it. I've a file with 4898 rows with 7 qualities and lineplot compute the median value (of alcohol variable) for each quality.

          – hganger
          Jan 1 at 10:17







          Thank you. However I don't understand how to apply it. I've a file with 4898 rows with 7 qualities and lineplot compute the median value (of alcohol variable) for each quality.

          – hganger
          Jan 1 at 10:17






          1




          1





          Finally, I did it thanks to your post and the offset idea. labels, uniques = pd.factorize(df['quality'], sort = True) sns.lineplot(x=labels, y=df['alcohol'], estimator=np.median, err_style=None, color='black') sns.stripplot(x='quality', y='alcohol', data=df, jitter=True, color='red', alpha=0.2, edgecolor='none')

          – hganger
          Jan 1 at 10:35







          Finally, I did it thanks to your post and the offset idea. labels, uniques = pd.factorize(df['quality'], sort = True) sns.lineplot(x=labels, y=df['alcohol'], estimator=np.median, err_style=None, color='black') sns.stripplot(x='quality', y='alcohol', data=df, jitter=True, color='red', alpha=0.2, edgecolor='none')

          – hganger
          Jan 1 at 10:35






















          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%2f53986627%2fstripplot-and-lineplot-weird-result%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

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]