Changing distance between categories when plotting FacetGrid with error barsHow to change the font size on a matplotlib plotWhen to use cla(), clf() or close() for clearing a plot in matplotlib?pandas plots on Seaborn FacetGridHow to add legend on Seaborn facetgrid bar plotIncrease space between rows on FacetGrid plotPython: Plot scatter plot with category and markersizePlotting mean lines for different 'hue' data on a Seaborn FacetGrid plotSeaborn FacetGrid legend loses linestyle details when changing linewidthseaborn bar chart for categorical data, groupedHow to add a comparison line to all plots when using Seaborn's FacetGrid

Will using a resistor in series with a LED to control its voltage increase the total energy expenditure?

Why does my purified Pokémon need to be healed?

Why did IBM make public the PC BIOS source code?

Simplification of numbers

What are those bumps on top of the Antonov-225?

Do Reform Jews believe in a theistic God?

If you know the location of an invisible creature, can you attack it?

How can God warn people of the upcoming rapture without disrupting society?

Boss asked a co-worker to assault me

How was the murder committed?

The cat exchanges places with a drawing of the cat

How far did Gandalf and the Balrog drop from the bridge in Moria?

Are those flyers about apartment purchase a scam?

Concat Loop Results to determine if contains value

How do I call a 6 digit Austrailian phone number with a US based mobile phone?

PhD advisor lost funding, need advice

Modeling the uncertainty of the input parameters

Does one make a shehecheyanu on "used" jewelry?

How do some PhD students get 10+ papers? Is that what I need for landing good faculty position?

What kind of liquid can be seen 'leaking' from the upper surface of the wing of a Boeing 737-800?

Telephone number in spoken words

Can the IPA represent all languages' tones?

Using hearing aids on the sabbath?

Help, I cannot decide when to start the story



Changing distance between categories when plotting FacetGrid with error bars


How to change the font size on a matplotlib plotWhen to use cla(), clf() or close() for clearing a plot in matplotlib?pandas plots on Seaborn FacetGridHow to add legend on Seaborn facetgrid bar plotIncrease space between rows on FacetGrid plotPython: Plot scatter plot with category and markersizePlotting mean lines for different 'hue' data on a Seaborn FacetGrid plotSeaborn FacetGrid legend loses linestyle details when changing linewidthseaborn bar chart for categorical data, groupedHow to add a comparison line to all plots when using Seaborn's FacetGrid






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








0















I am using FacetGrid from Seaborn together with errorbar from Matplotlib to generate a graph that has two categories in the y axis. I want to center the two categories (get them closer to each other and more distant to the margins).



I have tried to change height/aspect to achieve that without success. I am sharing the code below. Thanks!



import matplotlib.pyplot as plt 
import seaborn as sns
import pandas as pd

cat = ['a','b','a','a','a','b','b','a']
var=[3,5,4,6,7,5,6,3]
sd_var = [0.1,0.3,0.1,0.5,0.4,0.2,0.1,0.2]

df = pd.DataFrame('cat' : cat, 'var' : var, 'sd_var' : sd_var)

g = sns.FacetGrid(data=df, hue="cat", aspect=1, height=6)
g.map(plt.errorbar, "cat", "var", "sd_var", marker="o",
linestyle='',markersize='6', capsize=4, elinewidth=2)

plt.show()









share|improve this question
































    0















    I am using FacetGrid from Seaborn together with errorbar from Matplotlib to generate a graph that has two categories in the y axis. I want to center the two categories (get them closer to each other and more distant to the margins).



    I have tried to change height/aspect to achieve that without success. I am sharing the code below. Thanks!



    import matplotlib.pyplot as plt 
    import seaborn as sns
    import pandas as pd

    cat = ['a','b','a','a','a','b','b','a']
    var=[3,5,4,6,7,5,6,3]
    sd_var = [0.1,0.3,0.1,0.5,0.4,0.2,0.1,0.2]

    df = pd.DataFrame('cat' : cat, 'var' : var, 'sd_var' : sd_var)

    g = sns.FacetGrid(data=df, hue="cat", aspect=1, height=6)
    g.map(plt.errorbar, "cat", "var", "sd_var", marker="o",
    linestyle='',markersize='6', capsize=4, elinewidth=2)

    plt.show()









    share|improve this question




























      0












      0








      0








      I am using FacetGrid from Seaborn together with errorbar from Matplotlib to generate a graph that has two categories in the y axis. I want to center the two categories (get them closer to each other and more distant to the margins).



      I have tried to change height/aspect to achieve that without success. I am sharing the code below. Thanks!



      import matplotlib.pyplot as plt 
      import seaborn as sns
      import pandas as pd

      cat = ['a','b','a','a','a','b','b','a']
      var=[3,5,4,6,7,5,6,3]
      sd_var = [0.1,0.3,0.1,0.5,0.4,0.2,0.1,0.2]

      df = pd.DataFrame('cat' : cat, 'var' : var, 'sd_var' : sd_var)

      g = sns.FacetGrid(data=df, hue="cat", aspect=1, height=6)
      g.map(plt.errorbar, "cat", "var", "sd_var", marker="o",
      linestyle='',markersize='6', capsize=4, elinewidth=2)

      plt.show()









      share|improve this question
















      I am using FacetGrid from Seaborn together with errorbar from Matplotlib to generate a graph that has two categories in the y axis. I want to center the two categories (get them closer to each other and more distant to the margins).



      I have tried to change height/aspect to achieve that without success. I am sharing the code below. Thanks!



      import matplotlib.pyplot as plt 
      import seaborn as sns
      import pandas as pd

      cat = ['a','b','a','a','a','b','b','a']
      var=[3,5,4,6,7,5,6,3]
      sd_var = [0.1,0.3,0.1,0.5,0.4,0.2,0.1,0.2]

      df = pd.DataFrame('cat' : cat, 'var' : var, 'sd_var' : sd_var)

      g = sns.FacetGrid(data=df, hue="cat", aspect=1, height=6)
      g.map(plt.errorbar, "cat", "var", "sd_var", marker="o",
      linestyle='',markersize='6', capsize=4, elinewidth=2)

      plt.show()






      python matplotlib seaborn errorbar facet-grid






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 1:11







      Daniela Osorio

















      asked Mar 26 at 23:18









      Daniela OsorioDaniela Osorio

      11 bronze badge




      11 bronze badge

























          1 Answer
          1






          active

          oldest

          votes


















          0














          You are pretty close to it



          import matplotlib.pyplot as plt 
          import seaborn as sns
          import pandas as pd

          # replace label with actual number
          cat = [1,2,1,1,1,2,2,1]
          var=[3,5,4,6,7,5,6,3]
          sd_var = [0.1,0.3,0.1,0.5,0.4,0.2,0.1,0.2]

          df = pd.DataFrame('cat' : cat, 'var' : var, 'sd_var' : sd_var)

          g = sns.FacetGrid(data=df, hue="cat", aspect=1, height=6)
          g.map(plt.errorbar, "cat", "var", "sd_var", marker="o",
          linestyle='',markersize='6', capsize=4, elinewidth=2)

          # place the ticks at center by widening the plot
          plt.xlim((0, 3))
          # fix ticks at the number encoding for each class
          g.fig.axes[0].xaxis.set_ticks([1, 2])
          # name the numbers
          g.fig.axes[0].xaxis.set_ticklabels(['a', 'b'])
          plt.show()


          The trick is to make use of relative length of the x-limit and your number encoding for the classes.



          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%2f55367551%2fchanging-distance-between-categories-when-plotting-facetgrid-with-error-bars%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 are pretty close to it



            import matplotlib.pyplot as plt 
            import seaborn as sns
            import pandas as pd

            # replace label with actual number
            cat = [1,2,1,1,1,2,2,1]
            var=[3,5,4,6,7,5,6,3]
            sd_var = [0.1,0.3,0.1,0.5,0.4,0.2,0.1,0.2]

            df = pd.DataFrame('cat' : cat, 'var' : var, 'sd_var' : sd_var)

            g = sns.FacetGrid(data=df, hue="cat", aspect=1, height=6)
            g.map(plt.errorbar, "cat", "var", "sd_var", marker="o",
            linestyle='',markersize='6', capsize=4, elinewidth=2)

            # place the ticks at center by widening the plot
            plt.xlim((0, 3))
            # fix ticks at the number encoding for each class
            g.fig.axes[0].xaxis.set_ticks([1, 2])
            # name the numbers
            g.fig.axes[0].xaxis.set_ticklabels(['a', 'b'])
            plt.show()


            The trick is to make use of relative length of the x-limit and your number encoding for the classes.



            enter image description here






            share|improve this answer





























              0














              You are pretty close to it



              import matplotlib.pyplot as plt 
              import seaborn as sns
              import pandas as pd

              # replace label with actual number
              cat = [1,2,1,1,1,2,2,1]
              var=[3,5,4,6,7,5,6,3]
              sd_var = [0.1,0.3,0.1,0.5,0.4,0.2,0.1,0.2]

              df = pd.DataFrame('cat' : cat, 'var' : var, 'sd_var' : sd_var)

              g = sns.FacetGrid(data=df, hue="cat", aspect=1, height=6)
              g.map(plt.errorbar, "cat", "var", "sd_var", marker="o",
              linestyle='',markersize='6', capsize=4, elinewidth=2)

              # place the ticks at center by widening the plot
              plt.xlim((0, 3))
              # fix ticks at the number encoding for each class
              g.fig.axes[0].xaxis.set_ticks([1, 2])
              # name the numbers
              g.fig.axes[0].xaxis.set_ticklabels(['a', 'b'])
              plt.show()


              The trick is to make use of relative length of the x-limit and your number encoding for the classes.



              enter image description here






              share|improve this answer



























                0












                0








                0







                You are pretty close to it



                import matplotlib.pyplot as plt 
                import seaborn as sns
                import pandas as pd

                # replace label with actual number
                cat = [1,2,1,1,1,2,2,1]
                var=[3,5,4,6,7,5,6,3]
                sd_var = [0.1,0.3,0.1,0.5,0.4,0.2,0.1,0.2]

                df = pd.DataFrame('cat' : cat, 'var' : var, 'sd_var' : sd_var)

                g = sns.FacetGrid(data=df, hue="cat", aspect=1, height=6)
                g.map(plt.errorbar, "cat", "var", "sd_var", marker="o",
                linestyle='',markersize='6', capsize=4, elinewidth=2)

                # place the ticks at center by widening the plot
                plt.xlim((0, 3))
                # fix ticks at the number encoding for each class
                g.fig.axes[0].xaxis.set_ticks([1, 2])
                # name the numbers
                g.fig.axes[0].xaxis.set_ticklabels(['a', 'b'])
                plt.show()


                The trick is to make use of relative length of the x-limit and your number encoding for the classes.



                enter image description here






                share|improve this answer













                You are pretty close to it



                import matplotlib.pyplot as plt 
                import seaborn as sns
                import pandas as pd

                # replace label with actual number
                cat = [1,2,1,1,1,2,2,1]
                var=[3,5,4,6,7,5,6,3]
                sd_var = [0.1,0.3,0.1,0.5,0.4,0.2,0.1,0.2]

                df = pd.DataFrame('cat' : cat, 'var' : var, 'sd_var' : sd_var)

                g = sns.FacetGrid(data=df, hue="cat", aspect=1, height=6)
                g.map(plt.errorbar, "cat", "var", "sd_var", marker="o",
                linestyle='',markersize='6', capsize=4, elinewidth=2)

                # place the ticks at center by widening the plot
                plt.xlim((0, 3))
                # fix ticks at the number encoding for each class
                g.fig.axes[0].xaxis.set_ticks([1, 2])
                # name the numbers
                g.fig.axes[0].xaxis.set_ticklabels(['a', 'b'])
                plt.show()


                The trick is to make use of relative length of the x-limit and your number encoding for the classes.



                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 28 at 1:29









                PM HuiPM Hui

                1566 bronze badges




                1566 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%2f55367551%2fchanging-distance-between-categories-when-plotting-facetgrid-with-error-bars%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript