Python Forum
Change distance and title postion in subplots
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change distance and title postion in subplots
#1
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
Reply
#2
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()
Reply
#3
it is exactly what I am looking, Thanks a lot !

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 1,660 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  Nested for loops: Iterating over columns of a DataFrame to plot on subplots dm222 0 1,706 Aug-19-2022, 11:07 AM
Last Post: dm222
Question Error with MatPlotLib subplots Danno 8 3,408 Apr-01-2022, 12:23 AM
Last Post: Danno
  Extract text based on postion and pattern guddu_12 2 1,626 Sep-27-2021, 08:32 PM
Last Post: guddu_12
  Visualize Geo Map/Calculate distance zarize 1 1,891 Dec-05-2019, 08:36 PM
Last Post: Larz60+
  how to create subplots in for loop? python_newbie09 1 5,897 Sep-25-2019, 02:29 PM
Last Post: stullis
  euclidean distance jenya56 3 2,805 Mar-29-2019, 02:56 AM
Last Post: scidam
  Subplots on one figure SarahColombo96 0 1,742 Feb-09-2019, 01:09 PM
Last Post: SarahColombo96
  organizing by distance gonzo620 7 3,897 Oct-16-2018, 01:41 AM
Last Post: stullis
  How to change font size of chart title and axis title ? thrupass 5 15,560 Mar-30-2018, 04:02 PM
Last Post: DrFunn1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020