Matplotlib multiple subplots figure spacing as per requirement










1















A very simple question regarding spacing the matplotlib subplots, despite multiple iterations on plt.tight_layout or plt.subplots_adjust. I am still not able to bring the right space between the subplots



Following is a sample python code



import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline


dict1 = 'importance': 'var1': 67.18,'var2': 50.33,'var3': 29.33,
'var4': 27.17, 'var5': 24.880

dict2 = 'importance': 'var3': 50.18,'var1': 30.33,'var2': 29.33,
'var4': 24.17, 'var5': 7.880


df1 = pd.DataFrame.from_dict(dict1)
df2 = pd.DataFrame.from_dict(dict2)


fig, (ax1, ax2) = plt.subplots(1,2)
fig = plt.figure(figsize=(60,60))
fig.subplots_adjust(wspace=10)
df1.plot(kind = 'barh', ax = ax1)
df2.plot(kind = 'barh', ax = ax2)


So the graph isenter image description here



which is certainly not I am looking for, I am looking for a wide spread subplots. Pls Help










share|improve this question


























    1















    A very simple question regarding spacing the matplotlib subplots, despite multiple iterations on plt.tight_layout or plt.subplots_adjust. I am still not able to bring the right space between the subplots



    Following is a sample python code



    import pandas as pd
    import matplotlib.pyplot as plt
    %matplotlib inline


    dict1 = 'importance': 'var1': 67.18,'var2': 50.33,'var3': 29.33,
    'var4': 27.17, 'var5': 24.880

    dict2 = 'importance': 'var3': 50.18,'var1': 30.33,'var2': 29.33,
    'var4': 24.17, 'var5': 7.880


    df1 = pd.DataFrame.from_dict(dict1)
    df2 = pd.DataFrame.from_dict(dict2)


    fig, (ax1, ax2) = plt.subplots(1,2)
    fig = plt.figure(figsize=(60,60))
    fig.subplots_adjust(wspace=10)
    df1.plot(kind = 'barh', ax = ax1)
    df2.plot(kind = 'barh', ax = ax2)


    So the graph isenter image description here



    which is certainly not I am looking for, I am looking for a wide spread subplots. Pls Help










    share|improve this question
























      1












      1








      1








      A very simple question regarding spacing the matplotlib subplots, despite multiple iterations on plt.tight_layout or plt.subplots_adjust. I am still not able to bring the right space between the subplots



      Following is a sample python code



      import pandas as pd
      import matplotlib.pyplot as plt
      %matplotlib inline


      dict1 = 'importance': 'var1': 67.18,'var2': 50.33,'var3': 29.33,
      'var4': 27.17, 'var5': 24.880

      dict2 = 'importance': 'var3': 50.18,'var1': 30.33,'var2': 29.33,
      'var4': 24.17, 'var5': 7.880


      df1 = pd.DataFrame.from_dict(dict1)
      df2 = pd.DataFrame.from_dict(dict2)


      fig, (ax1, ax2) = plt.subplots(1,2)
      fig = plt.figure(figsize=(60,60))
      fig.subplots_adjust(wspace=10)
      df1.plot(kind = 'barh', ax = ax1)
      df2.plot(kind = 'barh', ax = ax2)


      So the graph isenter image description here



      which is certainly not I am looking for, I am looking for a wide spread subplots. Pls Help










      share|improve this question














      A very simple question regarding spacing the matplotlib subplots, despite multiple iterations on plt.tight_layout or plt.subplots_adjust. I am still not able to bring the right space between the subplots



      Following is a sample python code



      import pandas as pd
      import matplotlib.pyplot as plt
      %matplotlib inline


      dict1 = 'importance': 'var1': 67.18,'var2': 50.33,'var3': 29.33,
      'var4': 27.17, 'var5': 24.880

      dict2 = 'importance': 'var3': 50.18,'var1': 30.33,'var2': 29.33,
      'var4': 24.17, 'var5': 7.880


      df1 = pd.DataFrame.from_dict(dict1)
      df2 = pd.DataFrame.from_dict(dict2)


      fig, (ax1, ax2) = plt.subplots(1,2)
      fig = plt.figure(figsize=(60,60))
      fig.subplots_adjust(wspace=10)
      df1.plot(kind = 'barh', ax = ax1)
      df2.plot(kind = 'barh', ax = ax2)


      So the graph isenter image description here



      which is certainly not I am looking for, I am looking for a wide spread subplots. Pls Help







      python pandas matplotlib






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 6:59









      Manu SharmaManu Sharma

      306517




      306517






















          2 Answers
          2






          active

          oldest

          votes


















          1














          What you can do is:



          fig, (ax1, ax2) = plt.subplots(1,2,figsize=(10,10))
          fig.subplots_adjust(wspace=0.5)
          df1.plot(kind = 'barh', ax = ax1)
          df2.plot(kind = 'barh', ax = ax2)
          plt.show()


          Output:
          enter image description here






          share|improve this answer






























            2














            Your problem here is that fig = plt.figure(figsize=(60,60)) creates a second figure, so when you call fig.subplots_adjust(wspace=10), it modifies this second figure and not the one on which you have your plotting axes. A way to correct this is to first include the keyword figsize inside your call to subplots fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(60, 60), then remove the call to figure underneath and finally adjust the wspace value.






            share|improve this answer























            • Explained it really well, Thank you so much!

              – Manu Sharma
              Nov 13 '18 at 8:15










            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%2f53275462%2fmatplotlib-multiple-subplots-figure-spacing-as-per-requirement%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









            1














            What you can do is:



            fig, (ax1, ax2) = plt.subplots(1,2,figsize=(10,10))
            fig.subplots_adjust(wspace=0.5)
            df1.plot(kind = 'barh', ax = ax1)
            df2.plot(kind = 'barh', ax = ax2)
            plt.show()


            Output:
            enter image description here






            share|improve this answer



























              1














              What you can do is:



              fig, (ax1, ax2) = plt.subplots(1,2,figsize=(10,10))
              fig.subplots_adjust(wspace=0.5)
              df1.plot(kind = 'barh', ax = ax1)
              df2.plot(kind = 'barh', ax = ax2)
              plt.show()


              Output:
              enter image description here






              share|improve this answer

























                1












                1








                1







                What you can do is:



                fig, (ax1, ax2) = plt.subplots(1,2,figsize=(10,10))
                fig.subplots_adjust(wspace=0.5)
                df1.plot(kind = 'barh', ax = ax1)
                df2.plot(kind = 'barh', ax = ax2)
                plt.show()


                Output:
                enter image description here






                share|improve this answer













                What you can do is:



                fig, (ax1, ax2) = plt.subplots(1,2,figsize=(10,10))
                fig.subplots_adjust(wspace=0.5)
                df1.plot(kind = 'barh', ax = ax1)
                df2.plot(kind = 'barh', ax = ax2)
                plt.show()


                Output:
                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 '18 at 7:25









                JoeJoe

                5,96421329




                5,96421329























                    2














                    Your problem here is that fig = plt.figure(figsize=(60,60)) creates a second figure, so when you call fig.subplots_adjust(wspace=10), it modifies this second figure and not the one on which you have your plotting axes. A way to correct this is to first include the keyword figsize inside your call to subplots fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(60, 60), then remove the call to figure underneath and finally adjust the wspace value.






                    share|improve this answer























                    • Explained it really well, Thank you so much!

                      – Manu Sharma
                      Nov 13 '18 at 8:15















                    2














                    Your problem here is that fig = plt.figure(figsize=(60,60)) creates a second figure, so when you call fig.subplots_adjust(wspace=10), it modifies this second figure and not the one on which you have your plotting axes. A way to correct this is to first include the keyword figsize inside your call to subplots fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(60, 60), then remove the call to figure underneath and finally adjust the wspace value.






                    share|improve this answer























                    • Explained it really well, Thank you so much!

                      – Manu Sharma
                      Nov 13 '18 at 8:15













                    2












                    2








                    2







                    Your problem here is that fig = plt.figure(figsize=(60,60)) creates a second figure, so when you call fig.subplots_adjust(wspace=10), it modifies this second figure and not the one on which you have your plotting axes. A way to correct this is to first include the keyword figsize inside your call to subplots fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(60, 60), then remove the call to figure underneath and finally adjust the wspace value.






                    share|improve this answer













                    Your problem here is that fig = plt.figure(figsize=(60,60)) creates a second figure, so when you call fig.subplots_adjust(wspace=10), it modifies this second figure and not the one on which you have your plotting axes. A way to correct this is to first include the keyword figsize inside your call to subplots fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(60, 60), then remove the call to figure underneath and finally adjust the wspace value.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 13 '18 at 7:21









                    Patol75Patol75

                    6236




                    6236












                    • Explained it really well, Thank you so much!

                      – Manu Sharma
                      Nov 13 '18 at 8:15

















                    • Explained it really well, Thank you so much!

                      – Manu Sharma
                      Nov 13 '18 at 8:15
















                    Explained it really well, Thank you so much!

                    – Manu Sharma
                    Nov 13 '18 at 8:15





                    Explained it really well, Thank you so much!

                    – Manu Sharma
                    Nov 13 '18 at 8:15

















                    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%2f53275462%2fmatplotlib-multiple-subplots-figure-spacing-as-per-requirement%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

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo