How to do both things together: adjust subplot spacings and place the legend outside of the plot?How to put the legend out of the plotMatplotlib plots: removing axis, legends and white spaceshow do I make a single legend for many subplots with matplotlib?Placing the legend outside the plotlegend outside and adjusting subplot size shrink picturePlot and Scatter legend on subplotPut legend on a place of a subplotAdjusting space in-between subplotshow to configure title on Matplotlib barchart using SeabornEqually spacing matplotlib Gridspec plots with consideration of axes/ticklabels/titles

Failing students when it might cause them economic ruin

Why didn't Daenerys' advisers suggest assassinating Cersei?

refer string as a field API name

Why is it correct to use ~た in this sentence, even though we're talking about next week?

What is this rubber on gear cables

AD: OU for system administrator accounts

What kind of environment would favor hermaphroditism in a sentient species over regular, old sexes?

Physically unpleasant work environment

A person lacking money who shows off a lot

How can we delete item permanently without storing in Recycle Bin?

Usage of the relative pronoun "dont"

Why are there five extra turns in tournament Magic?

Why use a retrograde orbit?

How do Ctrl+C and Ctrl+V work?

How does the Heat Metal spell interact with a follow-up Frostbite spell?

Why is so much ransomware breakable?

Is it possible to pass a pointer to an operator as an argument like a pointer to a function?

I recently started my machine learning PhD and I have absolutely no idea what I'm doing

Why doesn't Iron Man's action affect this person in Endgame?

Would life always name the light from their sun "white"

Is there an academic word that means "to split hairs over"?

Resistor Selection to retain same brightness in LED PWM circuit

Why do academics prefer Mac/Linux?

How could it be that 80% of townspeople were farmers during the Edo period in Japan?



How to do both things together: adjust subplot spacings and place the legend outside of the plot?


How to put the legend out of the plotMatplotlib plots: removing axis, legends and white spaceshow do I make a single legend for many subplots with matplotlib?Placing the legend outside the plotlegend outside and adjusting subplot size shrink picturePlot and Scatter legend on subplotPut legend on a place of a subplotAdjusting space in-between subplotshow to configure title on Matplotlib barchart using SeabornEqually spacing matplotlib Gridspec plots with consideration of axes/ticklabels/titles






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have 9 matplotlib subplots arranged in a grid. I'm trying to do two simple things: (1) adjust subplot spacing to reduce white space, (2) place the legend outside of the plot. Individually, both things are super easy. Together, they don't work: If I place legend outside of the subplots using bbox_to_achnor=(...), subplot spacing gets messed up and subplots_adjust(...) don't work anymore.



UPD: This works for tight spacing:



fig, axes = plt.subplots(3, 3)

plt.subplot(331)
# plot something on every subplot
plt.subplot(339)
# plot something here too

plt.subplots_adjust(wspace=0, hspace=0)
plt.tight_layout()
plt.savefig("blabla.pdf", format="pdf")


And with this code all figures become squeezed:



fig, axes = plt.subplots(3, 3)

plt.subplot(331)
# plot something on every subplot
plt.subplot(339)
# plot something here too

# add outside legend to the first plot
plt.subplot(331)
lgd = plt.legend(ncol=1, loc=2, prop='size': 10, bbox_to_anchor=4.2, 0.2))

plt.subplots_adjust(wspace=0, hspace=0)
plt.tight_layout()
plt.savefig("blabla.pdf", format="pdf", bbox_inches="tight", bbox_extra_artists=(lgd,))


Any ideas?










share|improve this question






























    1















    I have 9 matplotlib subplots arranged in a grid. I'm trying to do two simple things: (1) adjust subplot spacing to reduce white space, (2) place the legend outside of the plot. Individually, both things are super easy. Together, they don't work: If I place legend outside of the subplots using bbox_to_achnor=(...), subplot spacing gets messed up and subplots_adjust(...) don't work anymore.



    UPD: This works for tight spacing:



    fig, axes = plt.subplots(3, 3)

    plt.subplot(331)
    # plot something on every subplot
    plt.subplot(339)
    # plot something here too

    plt.subplots_adjust(wspace=0, hspace=0)
    plt.tight_layout()
    plt.savefig("blabla.pdf", format="pdf")


    And with this code all figures become squeezed:



    fig, axes = plt.subplots(3, 3)

    plt.subplot(331)
    # plot something on every subplot
    plt.subplot(339)
    # plot something here too

    # add outside legend to the first plot
    plt.subplot(331)
    lgd = plt.legend(ncol=1, loc=2, prop='size': 10, bbox_to_anchor=4.2, 0.2))

    plt.subplots_adjust(wspace=0, hspace=0)
    plt.tight_layout()
    plt.savefig("blabla.pdf", format="pdf", bbox_inches="tight", bbox_extra_artists=(lgd,))


    Any ideas?










    share|improve this question


























      1












      1








      1








      I have 9 matplotlib subplots arranged in a grid. I'm trying to do two simple things: (1) adjust subplot spacing to reduce white space, (2) place the legend outside of the plot. Individually, both things are super easy. Together, they don't work: If I place legend outside of the subplots using bbox_to_achnor=(...), subplot spacing gets messed up and subplots_adjust(...) don't work anymore.



      UPD: This works for tight spacing:



      fig, axes = plt.subplots(3, 3)

      plt.subplot(331)
      # plot something on every subplot
      plt.subplot(339)
      # plot something here too

      plt.subplots_adjust(wspace=0, hspace=0)
      plt.tight_layout()
      plt.savefig("blabla.pdf", format="pdf")


      And with this code all figures become squeezed:



      fig, axes = plt.subplots(3, 3)

      plt.subplot(331)
      # plot something on every subplot
      plt.subplot(339)
      # plot something here too

      # add outside legend to the first plot
      plt.subplot(331)
      lgd = plt.legend(ncol=1, loc=2, prop='size': 10, bbox_to_anchor=4.2, 0.2))

      plt.subplots_adjust(wspace=0, hspace=0)
      plt.tight_layout()
      plt.savefig("blabla.pdf", format="pdf", bbox_inches="tight", bbox_extra_artists=(lgd,))


      Any ideas?










      share|improve this question
















      I have 9 matplotlib subplots arranged in a grid. I'm trying to do two simple things: (1) adjust subplot spacing to reduce white space, (2) place the legend outside of the plot. Individually, both things are super easy. Together, they don't work: If I place legend outside of the subplots using bbox_to_achnor=(...), subplot spacing gets messed up and subplots_adjust(...) don't work anymore.



      UPD: This works for tight spacing:



      fig, axes = plt.subplots(3, 3)

      plt.subplot(331)
      # plot something on every subplot
      plt.subplot(339)
      # plot something here too

      plt.subplots_adjust(wspace=0, hspace=0)
      plt.tight_layout()
      plt.savefig("blabla.pdf", format="pdf")


      And with this code all figures become squeezed:



      fig, axes = plt.subplots(3, 3)

      plt.subplot(331)
      # plot something on every subplot
      plt.subplot(339)
      # plot something here too

      # add outside legend to the first plot
      plt.subplot(331)
      lgd = plt.legend(ncol=1, loc=2, prop='size': 10, bbox_to_anchor=4.2, 0.2))

      plt.subplots_adjust(wspace=0, hspace=0)
      plt.tight_layout()
      plt.savefig("blabla.pdf", format="pdf", bbox_inches="tight", bbox_extra_artists=(lgd,))


      Any ideas?







      python matplotlib






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 16:10







      mck

















      asked Mar 23 at 15:55









      mckmck

      4318




      4318






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Things will supposedly work fine if you use the legend with the figure object fig. Currently you use it with the last plt object which correspond to the last subfigure 339. Using fig, you don't need a large offset of 4.2 for the bbox_to_anchor. Something like 1.1 or 1.2 should work fine



          lgd = fig.legend(ncol=1, loc=2, prop='size': 10, bbox_to_anchor=(1.2, 0.2))





          share|improve this answer























          • Thanks a lot for the advice! The trick worked for me. I'm having hard time to understand why this "squeeze" effect occur though.

            – mck
            Mar 24 at 15:20











          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%2f55315594%2fhow-to-do-both-things-together-adjust-subplot-spacings-and-place-the-legend-out%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














          Things will supposedly work fine if you use the legend with the figure object fig. Currently you use it with the last plt object which correspond to the last subfigure 339. Using fig, you don't need a large offset of 4.2 for the bbox_to_anchor. Something like 1.1 or 1.2 should work fine



          lgd = fig.legend(ncol=1, loc=2, prop='size': 10, bbox_to_anchor=(1.2, 0.2))





          share|improve this answer























          • Thanks a lot for the advice! The trick worked for me. I'm having hard time to understand why this "squeeze" effect occur though.

            – mck
            Mar 24 at 15:20















          1














          Things will supposedly work fine if you use the legend with the figure object fig. Currently you use it with the last plt object which correspond to the last subfigure 339. Using fig, you don't need a large offset of 4.2 for the bbox_to_anchor. Something like 1.1 or 1.2 should work fine



          lgd = fig.legend(ncol=1, loc=2, prop='size': 10, bbox_to_anchor=(1.2, 0.2))





          share|improve this answer























          • Thanks a lot for the advice! The trick worked for me. I'm having hard time to understand why this "squeeze" effect occur though.

            – mck
            Mar 24 at 15:20













          1












          1








          1







          Things will supposedly work fine if you use the legend with the figure object fig. Currently you use it with the last plt object which correspond to the last subfigure 339. Using fig, you don't need a large offset of 4.2 for the bbox_to_anchor. Something like 1.1 or 1.2 should work fine



          lgd = fig.legend(ncol=1, loc=2, prop='size': 10, bbox_to_anchor=(1.2, 0.2))





          share|improve this answer













          Things will supposedly work fine if you use the legend with the figure object fig. Currently you use it with the last plt object which correspond to the last subfigure 339. Using fig, you don't need a large offset of 4.2 for the bbox_to_anchor. Something like 1.1 or 1.2 should work fine



          lgd = fig.legend(ncol=1, loc=2, prop='size': 10, bbox_to_anchor=(1.2, 0.2))






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 16:19









          SheldoreSheldore

          17k31330




          17k31330












          • Thanks a lot for the advice! The trick worked for me. I'm having hard time to understand why this "squeeze" effect occur though.

            – mck
            Mar 24 at 15:20

















          • Thanks a lot for the advice! The trick worked for me. I'm having hard time to understand why this "squeeze" effect occur though.

            – mck
            Mar 24 at 15:20
















          Thanks a lot for the advice! The trick worked for me. I'm having hard time to understand why this "squeeze" effect occur though.

          – mck
          Mar 24 at 15:20





          Thanks a lot for the advice! The trick worked for me. I'm having hard time to understand why this "squeeze" effect occur though.

          – mck
          Mar 24 at 15:20



















          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%2f55315594%2fhow-to-do-both-things-together-adjust-subplot-spacings-and-place-the-legend-out%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

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해