1

I am using subplots side by side

plt.subplot(1, 2, 1)
# plot 1
plt.xlabel('MEM SET')
plt.ylabel('Memory Used')
plt.bar(inst_memory['MEMORY_SET_TYPE'], inst_memory['USED_MB'], alpha = 0.5, color = 'r')
# pol 2
plt.subplot(1, 2, 2)
plt.xlabel('MEM POOL')
plt.ylabel('Memory Used')
plt.bar(set_memory['POOL_TYPE'], set_memory['MEMORY_POOL_USED'], alpha = 0.5, color = 'g')

they have identical size - but is it possible to define the width for each subplot, so the right one could be wider as it has more entries and text would not squeeze or would it be possible to replace the bottom x-text by a number and have a legend with 1:means xx 2:means yyy enter image description here

jayveesea
  • 2,886
  • 13
  • 25

1 Answers1

1

I find GridSpec helpful for subplot arrangements, see this demo at matplotlib.

import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
import pandas as pd
N=24

inst_memory = pd.DataFrame({'MEMORY_SET_TYPE': np.random.randint(0,3,N),
                   'USED_MB': np.random.randint(0,1000,N)})
set_memory = pd.DataFrame({'MEMORY_POOL_USED': np.random.randint(0,1000,N),
                   'POOL_TYPE': np.random.randint(0,10,N)})

fig = plt.figure()
gs = GridSpec(1, 2, width_ratios=[1, 2],wspace=0.3)
ax1 = fig.add_subplot(gs[0])
ax2 = fig.add_subplot(gs[1])

ax1.bar(inst_memory['MEMORY_SET_TYPE'], inst_memory['USED_MB'], alpha = 0.5, color = 'r')
ax2.bar(set_memory['POOL_TYPE'], set_memory['MEMORY_POOL_USED'], alpha = 0.5, color = 'g')

You may need to adjust width_ratios and wspace to get the desired layout.

Also, rotating the text in x-axis might help, some info here.

jayveesea
  • 2,886
  • 13
  • 25
  • yes, thanks - I have used gridspec for sizing and rotate for x-labels... many thanks for all answers.. best regards, Guy – Guy Przytula May 20 '20 at 14:33