Search code examples
pythonplotfullscreenfiguresubplot

Python figure plots on half screen


I have the following code and am really struggling to get the plot on the whole screen.

fig = plt.figure()
fig.subplots_adjust(bottom=0.2)
ax1 = fig.add_subplot(212)
ax1.set_xlabel('Time')
ax1.set_ylim(0,time)
line1 = ax1.plot(a,'bo-',label='One')
line2 = ax1.plot(b,'mo-',label='Two')
lines = line1 + line2
labels = [l.get_label() for l in lines]
ax1.legend(lines, labels, loc=(0,-0.5), ncol=2)
plt.show()

I tried all the answers I found on the web and all the suggestions in the thread Extend python plots to full screen, none of them worked.

Any help would be appreciated!

P.S. I'm not using

t = np.arange(b)
plt.plot(t, a, 'bo-')

for example because it doesn't work if the x and y values are not the same and I cannot predefine x as it varies for my program.


Solution

  • The line

    ax1 = fig.add_subplot(212)
    

    creates a 2x1 plot and returns the second sub-plot. If you want a single plot, change this line to

    ax1 = fig.add_subplot(111)
    

    i.e 1x1 split returning the single sub-plot.