0

I have a simple grouped barplot, as in the example given below. I don't like the fact that the end result turns out quite large, and would like to change the height - but without changing the width. This is presumably quite simple, but I cannot figure it out.

How can I achieve this, and similarly, how could I change the width?

EDIT: So thanks to this question (it is also in the duplicate question, slightly hidden) I finally found out that I have been placing the figure resizing command

plt.figure(figsize=(10,15))

at the wrong place in the code all the time. If I place it directly after

sns.set(style='white')

the figure size actually does change.

However, now I get two popup windows: one named Figure 1 (the one that I want), and a second small line graph named Figure 2. Additionally, I get a warning:

QWindowsWindow::setGeometry: Unable to set geometry 1000x1566+8+31 on QWidgetWindow/'MainWindowClassWindow'. 
Resulting geometry:  1000x749+8+31 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 67x66, maximum size: 16777215x16777215).
QWindowsWindow::setGeometry: Unable to set geometry 100x166+633+281 on QWidgetWindow/'MainWindowClassWindow'. 
Resulting geometry:  124x166+633+281 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 67x66, maximum size: 16777215x16777215).

Interestingly, I only get the second popup and the warning in the simplified example below, and not when making the actual graph that this is a simplification of. I would be curious to know why this is.

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

title = 'Title'
parts = ['A', 'B', 'C', 'D'] 
items = ['one','two','three','four','five']

sns.set(style='white')
plt.title(title,fontsize=18)
ax = plt.gca()
ax.grid(which='major', axis='y', linestyle=':')

plt.xlabel('Item', fontsize=16)
pos = np.arange(len(items))
plt.xticks(pos, items)
plt.ylabel('Count', fontsize=16)
y_ticks = [0, 20, 40, 60, 80]
ax.set_yticks(y_ticks, minor=False)

full_bar_width = 0.2
bar_width = 0.15

all_A = [72, 74, 74, 70, 72]
all_B = [67, 69, 67, 65, 67]
all_C =  [67, 67, 64, 63, 65]
all_D = [57, 64, 57, 55, 58]

plt.bar(pos-(1.5*full_bar_width),all_A,bar_width,color='red')
plt.bar(pos-(0.5*full_bar_width),all_B,bar_width,color='blue')
plt.bar(pos+(0.5*full_bar_width),all_C,bar_width,color='cyan')
plt.bar(pos+(1.5*full_bar_width),all_D,bar_width,color='green')

plt.legend(parts,bbox_to_anchor=(1.04,0.5), loc='center left')
plt.subplots_adjust(right=0.8)
plt.show()
rdv
  • 682
  • 2
  • 8
  • 19
  • @ImportanceOfBeingErnest Before asking this question, I actually tried most of the things from the link you provided (and from other places) - but I am not a Matplotlib expert by far so I couldn't get it to work. Could you please point me a little closer to what exactly the solution is? – rdv Sep 29 '19 at 21:58
  • Any answer from that thread will help and you have not tried a single one in the code you show. – ImportanceOfBeingErnest Sep 29 '19 at 22:04
  • I haven't put my attempts in the code because I thought it would make no sense to muddle it up with things that don't work. Unlike what you seem to imply, I have spent quite some time trying the different answers. I figured that any time more spent would be spent wiser writing a question here. I guess I was wrong! – rdv Sep 29 '19 at 23:09
  • It is absolutely straight forward to change the figure size as in any of those answers. If they don't work, it means something else is wrong; but one can only find out what it is if seeing the code which doesn't work. – ImportanceOfBeingErnest Sep 29 '19 at 23:17
  • Your code does not contain any command to change the figure size. Instead the answers in the duplicate show how to do it. Copy one of them into your code and run it. – ImportanceOfBeingErnest Sep 29 '19 at 23:59
  • Well, that is exactly what I have been doing all the time! I have tried the top four answers and the comments on the original question as well. I either get a second popup, some superimposed second plot, or no change at all. I am stumped. – rdv Sep 30 '19 at 00:11
  • We're turning in circles here. ***Show*** what you have tried so one can find out where you took the wrong turn. – ImportanceOfBeingErnest Sep 30 '19 at 00:12

0 Answers0