Python Forum

Full Version: Change distance and title postion in subplots
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Forum

Problem: side by side plots too close, second plot title overlapping first plot
Does anybody know a way to fix this?

[url=[Image: S0eeSBG.png]]my plots[/url]

My code looks like so;
 import matplotlib.pyplot as plt
x1 = [1, 2, 3, 4]
y1 = [1, 4, 9, 16]
e1 = [0.5, 1., 1.5, 2.]
x2 = [1, 2, 3, 4]
y2 = [1, 4, 9, 16]
e2 = [0.5, 1., 1.5, 2.]
 


# Create plots with pre-defined labels.
fig, ((ax, ax1)) = plt.subplots(1, 2)
ax.plot(x1, y1, 'ko', label = 'Anode')
ax.errorbar(x1, y1, yerr=e1, fmt='o')


#plotting first plot 

ax.set_xlabel('Time (hour)')
ax.set_ylabel('Conc. (mg N) /3.0V')
ax.set_title(r'Ammonia migration Low ammonia conc')
legend = ax.legend(loc='upper right', shadow=False, fontsize='large')


# Put a nicer background color on the legend.
legend.get_frame().set_facecolor('#00FFCC')
              
#plotting second plot 
ax1.plot(x2, y2, 'ko', label = 'Anode')
ax1.errorbar(x2, y2, yerr=e2, fmt='o')



ax1.set_xlabel('Time (hour)')
ax1.set_ylabel('3.5V')

legend = ax1.legend(loc='upper right', shadow=False, fontsize='large')
# Put a nicer background color on the legend.
legend.get_frame().set_facecolor('#00FFCC')

plt.show() 
Thank you for your time
BR Mark
Check if tight_layout() is what your are looking for.

...
# Put a nicer background color on the legend.
legend.get_frame().set_facecolor('#00FFCC')

plt.tight_layout()
plt.show()
it is exactly what I am looking, Thanks a lot !

[url=[Image: tcAIG9h.png]]solution to problem[/url]