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;
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
add a comment |
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
add a comment |
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
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
python matplotlib
edited Mar 23 at 16:10
mck
asked Mar 23 at 15:55
mckmck
4318
4318
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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))
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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))
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
add a comment |
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))
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
add a comment |
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))
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))
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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