Matplotlib multiple subplots figure spacing as per requirement
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 is
which is certainly not I am looking for, I am looking for a wide spread subplots. Pls Help
python pandas matplotlib
add a comment |
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 is
which is certainly not I am looking for, I am looking for a wide spread subplots. Pls Help
python pandas matplotlib
add a comment |
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 is
which is certainly not I am looking for, I am looking for a wide spread subplots. Pls Help
python pandas matplotlib
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 is
which is certainly not I am looking for, I am looking for a wide spread subplots. Pls Help
python pandas matplotlib
python pandas matplotlib
asked Nov 13 '18 at 6:59
Manu SharmaManu Sharma
306517
306517
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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:
add a comment |
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.
Explained it really well, Thank you so much!
– Manu Sharma
Nov 13 '18 at 8:15
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%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
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:
add a comment |
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:
add a comment |
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:
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:
answered Nov 13 '18 at 7:25
JoeJoe
5,96421329
5,96421329
add a comment |
add a comment |
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.
Explained it really well, Thank you so much!
– Manu Sharma
Nov 13 '18 at 8:15
add a comment |
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.
Explained it really well, Thank you so much!
– Manu Sharma
Nov 13 '18 at 8:15
add a comment |
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.
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.
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
add a comment |
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
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%2f53275462%2fmatplotlib-multiple-subplots-figure-spacing-as-per-requirement%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