How to add droplines to a seaborn scatterplot?How do you change the size of figures drawn with matplotlib?How to put the legend out of the plotSeaborn plots not showing upScatterplot without linear fit in seabornWhy do sns.lmplot and FacetGrid+plt.scatter create different scatter points from the same data?Matplotlib Style Not Being AppliedPython: Plot scatter plot with category and markersizeIssue with xticklabels when saving a figure with matplotlibPandas boxplot, different y axes in subplotsQ: ModuleNotFoundError: No module named 'matplotlib.pyplot', etc

Why put copper in between battery contacts and clamps?

How to have poached eggs in "sphere form"?

What is my clock telling me to do?

Do the books ever say oliphaunts aren’t elephants?

Antonym of "Megalomania"

Will the temperature of stop-bath and fixer during development affect the final result?

GNU sort stable sort when sort does not know sort order

A variant of the Multiple Traveling Salesman Problem

What is the German equivalent of the proverb 水清ければ魚棲まず (if the water is clear, fish won't live there)?

Is there a word to describe someone who is, or the state of being, content with hanging around others without interacting with them?

What is the reason for cards stating "Until end of turn, you don't lose this mana as steps and phases end"?

Is it okay for me to decline a project on ethical grounds?

Why are subdominants unstable?

Why did the natural major scale and the minor scales come to dominate common practice music?

Should students have access to past exams or an exam bank?

Are there galaxies with 2 or more super massive black holes orbiting each other?

What clothes would flying-people wear?

Can a US President, after impeachment and removal, be re-elected or re-appointed?

Microgravity indicators

Why did some Apollo missions carry a grenade launcher?

Was the Psych theme song written for the show?

What is more environmentally friendly? An A320 or a car?

Can I attune a Circlet of Human Perfection to my animated skeletons to allow them to blend in and speak?

Why would anyone ever invest in a cash-only etf?



How to add droplines to a seaborn scatterplot?


How do you change the size of figures drawn with matplotlib?How to put the legend out of the plotSeaborn plots not showing upScatterplot without linear fit in seabornWhy do sns.lmplot and FacetGrid+plt.scatter create different scatter points from the same data?Matplotlib Style Not Being AppliedPython: Plot scatter plot with category and markersizeIssue with xticklabels when saving a figure with matplotlibPandas boxplot, different y axes in subplotsQ: ModuleNotFoundError: No module named 'matplotlib.pyplot', etc






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Using the following example code in a Jupyter notebook:



import pandas as pd
import seaborn as sns
import numpy as np

%matplotlib inline
%config InlineBackend.figure_format = 'svg'

df = pd.DataFrame(np.random.rand(5, 2), columns=['a', 'b'])
sns.set()
g = sns.relplot(data=df, x='a', y='b', kind='scatter');
g.set(xlim=(0, 1))
g.set(ylim=(0, 1));


The resulting plot shows the data points, but I would also like to have vertical drop lines and occasionally horizontal ones as well. To clarify what I mean by droplines, here is a mockup of the actual vs. the desired output:



Actual vs desired output



Update: A little more complex input that makes it harder to manually draw the lines:



import pandas as pd
import seaborn as sns
import numpy as np

%matplotlib inline
%config InlineBackend.figure_format = 'svg'

df = pd.DataFrame(np.random.rand(20, 3), columns=['a', 'b', 'c'])
df['d'] = ['apples', 'bananas', 'cherries', 'dates'] * 5
sns.set()
g = sns.relplot(data=df, x='a', y='b', hue='c', col='d', col_wrap=2, kind='scatter');
g.set(xlim=(0, 1))
g.set(ylim=(0, 1));









share|improve this question


























  • If (x0, y0) is the point to create a line for, the respective line would be plt.plot([x0, x0, 0], [0, y0, y0]), right?

    – ImportanceOfBeingErnest
    Mar 26 at 21:24

















0















Using the following example code in a Jupyter notebook:



import pandas as pd
import seaborn as sns
import numpy as np

%matplotlib inline
%config InlineBackend.figure_format = 'svg'

df = pd.DataFrame(np.random.rand(5, 2), columns=['a', 'b'])
sns.set()
g = sns.relplot(data=df, x='a', y='b', kind='scatter');
g.set(xlim=(0, 1))
g.set(ylim=(0, 1));


The resulting plot shows the data points, but I would also like to have vertical drop lines and occasionally horizontal ones as well. To clarify what I mean by droplines, here is a mockup of the actual vs. the desired output:



Actual vs desired output



Update: A little more complex input that makes it harder to manually draw the lines:



import pandas as pd
import seaborn as sns
import numpy as np

%matplotlib inline
%config InlineBackend.figure_format = 'svg'

df = pd.DataFrame(np.random.rand(20, 3), columns=['a', 'b', 'c'])
df['d'] = ['apples', 'bananas', 'cherries', 'dates'] * 5
sns.set()
g = sns.relplot(data=df, x='a', y='b', hue='c', col='d', col_wrap=2, kind='scatter');
g.set(xlim=(0, 1))
g.set(ylim=(0, 1));









share|improve this question


























  • If (x0, y0) is the point to create a line for, the respective line would be plt.plot([x0, x0, 0], [0, y0, y0]), right?

    – ImportanceOfBeingErnest
    Mar 26 at 21:24













0












0








0








Using the following example code in a Jupyter notebook:



import pandas as pd
import seaborn as sns
import numpy as np

%matplotlib inline
%config InlineBackend.figure_format = 'svg'

df = pd.DataFrame(np.random.rand(5, 2), columns=['a', 'b'])
sns.set()
g = sns.relplot(data=df, x='a', y='b', kind='scatter');
g.set(xlim=(0, 1))
g.set(ylim=(0, 1));


The resulting plot shows the data points, but I would also like to have vertical drop lines and occasionally horizontal ones as well. To clarify what I mean by droplines, here is a mockup of the actual vs. the desired output:



Actual vs desired output



Update: A little more complex input that makes it harder to manually draw the lines:



import pandas as pd
import seaborn as sns
import numpy as np

%matplotlib inline
%config InlineBackend.figure_format = 'svg'

df = pd.DataFrame(np.random.rand(20, 3), columns=['a', 'b', 'c'])
df['d'] = ['apples', 'bananas', 'cherries', 'dates'] * 5
sns.set()
g = sns.relplot(data=df, x='a', y='b', hue='c', col='d', col_wrap=2, kind='scatter');
g.set(xlim=(0, 1))
g.set(ylim=(0, 1));









share|improve this question
















Using the following example code in a Jupyter notebook:



import pandas as pd
import seaborn as sns
import numpy as np

%matplotlib inline
%config InlineBackend.figure_format = 'svg'

df = pd.DataFrame(np.random.rand(5, 2), columns=['a', 'b'])
sns.set()
g = sns.relplot(data=df, x='a', y='b', kind='scatter');
g.set(xlim=(0, 1))
g.set(ylim=(0, 1));


The resulting plot shows the data points, but I would also like to have vertical drop lines and occasionally horizontal ones as well. To clarify what I mean by droplines, here is a mockup of the actual vs. the desired output:



Actual vs desired output



Update: A little more complex input that makes it harder to manually draw the lines:



import pandas as pd
import seaborn as sns
import numpy as np

%matplotlib inline
%config InlineBackend.figure_format = 'svg'

df = pd.DataFrame(np.random.rand(20, 3), columns=['a', 'b', 'c'])
df['d'] = ['apples', 'bananas', 'cherries', 'dates'] * 5
sns.set()
g = sns.relplot(data=df, x='a', y='b', hue='c', col='d', col_wrap=2, kind='scatter');
g.set(xlim=(0, 1))
g.set(ylim=(0, 1));






matplotlib seaborn






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 7:44







Zoltan

















asked Mar 26 at 21:15









ZoltanZoltan

1,6235 silver badges16 bronze badges




1,6235 silver badges16 bronze badges















  • If (x0, y0) is the point to create a line for, the respective line would be plt.plot([x0, x0, 0], [0, y0, y0]), right?

    – ImportanceOfBeingErnest
    Mar 26 at 21:24

















  • If (x0, y0) is the point to create a line for, the respective line would be plt.plot([x0, x0, 0], [0, y0, y0]), right?

    – ImportanceOfBeingErnest
    Mar 26 at 21:24
















If (x0, y0) is the point to create a line for, the respective line would be plt.plot([x0, x0, 0], [0, y0, y0]), right?

– ImportanceOfBeingErnest
Mar 26 at 21:24





If (x0, y0) is the point to create a line for, the respective line would be plt.plot([x0, x0, 0], [0, y0, y0]), right?

– ImportanceOfBeingErnest
Mar 26 at 21:24












1 Answer
1






active

oldest

votes


















1














There are several ways to plot vertical/horizontal lines. One of the is to use hlines or vlines. This can be done using a loop for sake of ease.



import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np; np.random.seed(121)

fig, ax = plt.subplots()

df = pd.DataFrame(np.random.rand(5, 2), columns=['a', 'b'])
sns.set()
g = sns.relplot(data=df, x='a', y='b', kind='scatter', color='blue', ax=ax);

for x, y in zip(df['a'], df['b']):
ax.hlines(y, 0, x, color='blue')
ax.vlines(x, 0, y, color='blue')
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)

plt.close(g.fig)


enter image description here






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%2f55366296%2fhow-to-add-droplines-to-a-seaborn-scatterplot%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









    1














    There are several ways to plot vertical/horizontal lines. One of the is to use hlines or vlines. This can be done using a loop for sake of ease.



    import pandas as pd
    import seaborn as sns
    import matplotlib.pyplot as plt
    import numpy as np; np.random.seed(121)

    fig, ax = plt.subplots()

    df = pd.DataFrame(np.random.rand(5, 2), columns=['a', 'b'])
    sns.set()
    g = sns.relplot(data=df, x='a', y='b', kind='scatter', color='blue', ax=ax);

    for x, y in zip(df['a'], df['b']):
    ax.hlines(y, 0, x, color='blue')
    ax.vlines(x, 0, y, color='blue')
    ax.set_xlim(0, 1)
    ax.set_ylim(0, 1)

    plt.close(g.fig)


    enter image description here






    share|improve this answer































      1














      There are several ways to plot vertical/horizontal lines. One of the is to use hlines or vlines. This can be done using a loop for sake of ease.



      import pandas as pd
      import seaborn as sns
      import matplotlib.pyplot as plt
      import numpy as np; np.random.seed(121)

      fig, ax = plt.subplots()

      df = pd.DataFrame(np.random.rand(5, 2), columns=['a', 'b'])
      sns.set()
      g = sns.relplot(data=df, x='a', y='b', kind='scatter', color='blue', ax=ax);

      for x, y in zip(df['a'], df['b']):
      ax.hlines(y, 0, x, color='blue')
      ax.vlines(x, 0, y, color='blue')
      ax.set_xlim(0, 1)
      ax.set_ylim(0, 1)

      plt.close(g.fig)


      enter image description here






      share|improve this answer





























        1












        1








        1







        There are several ways to plot vertical/horizontal lines. One of the is to use hlines or vlines. This can be done using a loop for sake of ease.



        import pandas as pd
        import seaborn as sns
        import matplotlib.pyplot as plt
        import numpy as np; np.random.seed(121)

        fig, ax = plt.subplots()

        df = pd.DataFrame(np.random.rand(5, 2), columns=['a', 'b'])
        sns.set()
        g = sns.relplot(data=df, x='a', y='b', kind='scatter', color='blue', ax=ax);

        for x, y in zip(df['a'], df['b']):
        ax.hlines(y, 0, x, color='blue')
        ax.vlines(x, 0, y, color='blue')
        ax.set_xlim(0, 1)
        ax.set_ylim(0, 1)

        plt.close(g.fig)


        enter image description here






        share|improve this answer















        There are several ways to plot vertical/horizontal lines. One of the is to use hlines or vlines. This can be done using a loop for sake of ease.



        import pandas as pd
        import seaborn as sns
        import matplotlib.pyplot as plt
        import numpy as np; np.random.seed(121)

        fig, ax = plt.subplots()

        df = pd.DataFrame(np.random.rand(5, 2), columns=['a', 'b'])
        sns.set()
        g = sns.relplot(data=df, x='a', y='b', kind='scatter', color='blue', ax=ax);

        for x, y in zip(df['a'], df['b']):
        ax.hlines(y, 0, x, color='blue')
        ax.vlines(x, 0, y, color='blue')
        ax.set_xlim(0, 1)
        ax.set_ylim(0, 1)

        plt.close(g.fig)


        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 27 at 8:19









        Zoltan

        1,6235 silver badges16 bronze badges




        1,6235 silver badges16 bronze badges










        answered Mar 26 at 21:27









        SheldoreSheldore

        21.7k5 gold badges15 silver badges37 bronze badges




        21.7k5 gold badges15 silver badges37 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            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%2f55366296%2fhow-to-add-droplines-to-a-seaborn-scatterplot%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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            위키백과:대문 둘러보기 메뉴기부 안내모바일판 대문크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0CebuanoDeutschEnglishEspañolFrançaisItaliano日本語NederlandsPolskiPortuguêsРусскийSvenskaTiếng ViệtWinaray中文العربيةCatalàفارسیSrpskiУкраїнськаБългарскиНохчийнČeštinaDanskEsperantoEuskaraSuomiעבריתMagyarՀայերենBahasa IndonesiaҚазақшаBaso MinangkabauBahasa MelayuBân-lâm-gúNorskRomânăSrpskohrvatskiSlovenčinaTürkçe