0

first of all a lot of love to this forum. It has taught me so much already. But now I stumbled over a problem, I wasn't able to find a answer that worked for me. So here my first question on this forum.

My problem is, that my figure title that's supposed to be above my plots appears inside my first plot. Example Code:

fig = plt.figure(figsize=(10,10))
fig.suptitle('Titel', fontsize=50)
ax1 = fig.add_subplot(2,2,(1,2))
ax2 = fig.add_subplot(223)
ax3 = fig.add_subplot(224)

plt.show()

That's how it looks

I have experimented with

plt.subplots_adjust

and other things like tight_layout and so on, but to be honest, Im often confused by the matplotlib syntax and its different formulations.

I feel like there should be a easy solution, but maybe I googled the wrong things. Thank u for ur help :)

Edit: The problem appeard through my enviroment Pycharm in scentific mode

Samsul Islam
  • 2,581
  • 2
  • 17
  • 23
Mr D Omas
  • 1
  • 1

1 Answers1

0

Try this:

fig = plt.figure(figsize=(10,10))
ax1 = fig.add_subplot(2,2,(1,2))
ax2 = fig.add_subplot(223)
ax3 = fig.add_subplot(224)
plt.title('Title', fontsize=50)
plt.show()

enter image description here

pakpe
  • 5,391
  • 2
  • 8
  • 23
  • Thank u for the answer, but I get the same result as before with your code, but if it works for you then maybe it is a problem with my IDE. I use Pycharm Pro in scientific mode. – Mr D Omas Feb 20 '21 at 03:27
  • what I really not understand is that: 'plt.tight_layout(pad=, w_pad=, h_pad=)' does not change anything. Could it really be possible that pycharm reformats the plot ? – Mr D Omas Feb 20 '21 at 03:41
  • Yes, it has to be a problem with your environment. Also try plt.title instead of plt.suptitle to see if it works. – pakpe Feb 20 '21 at 03:41
  • I found the setting Tools -> Python Scentific -> Show plots in tool window. And there it works. Strange but thanks for the referenz which lead me to the solution – Mr D Omas Feb 20 '21 at 03:49
  • yes the plt.title thing works also, nice. This matplotlib syntax confuses me always, the plt, axs, figure, gridspec etc. formulation are all alike but different :D and when I solved one problen in the one I find the solution to my next problem online in a diffrent formulation. How ever thanks for ur help :) – Mr D Omas Feb 20 '21 at 03:54
  • You are welcome. I edited the answer to reflect plt.title. Please go ahead and accept the answer if you feel it has worked for you. – pakpe Feb 20 '21 at 03:58
  • Welcome to Stack Overflow. Here are the rules of etiquette on this site: https://stackoverflow.com/help/someone-answers – pakpe Feb 20 '21 at 04:13