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 3,644 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  Nested for loops: Iterating over columns of a DataFrame to plot on subplots dm222 0 3,570 Aug-19-2022, 11:07 AM
Last Post: dm222
Question Error with MatPlotLib subplots Danno 8 9,322 Apr-01-2022, 12:23 AM
Last Post: Danno
  Controller Buzzer as Distance Decreases barkster 6 4,581 Nov-01-2021, 03:26 PM
Last Post: barkster
  Extract text based on postion and pattern guddu_12 2 2,963 Sep-27-2021, 08:32 PM
Last Post: guddu_12
  broadcasting euclidean distance error glennford49 1 5,925 Nov-19-2020, 07:01 PM
Last Post: Gribouillis
  smallest Cosine distance in Graph vino689 3 3,826 Jan-12-2020, 08:06 AM
Last Post: rmspacedashrf
  Visualize Geo Map/Calculate distance zarize 1 2,924 Dec-05-2019, 08:36 PM
Last Post: Larz60+
  how to show the distance between two curves in a graph termo 6 10,090 Oct-21-2019, 09:08 AM
Last Post: DeaD_EyE
  how to create subplots in for loop? python_newbie09 1 7,610 Sep-25-2019, 02:29 PM
Last Post: stullis

Forum Jump:

User Panel Messages

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