Home > database >  x label is outside of my figure because of figsize
x label is outside of my figure because of figsize

Time:12-03

I am constructing a simple graph with the following code:

    plt.figure(figsize=(7, 3))
    plt.plot(idl_t, idl_q, color="blue", lw=2)
    plt.plot(dsc_t, dsc_q, color="red", lw=2)
    plt.plot(cha_t, cha_q, color="green", lw=2)
    plt.xlabel("Time (hour)")
    plt.show()

with input data as following:

    idl_t, idl_q = [[0, 20], [8, 24]], [[100, 100], [100, 100]]
    dsc_t, dsc_q = [[8, 14], [12, 18]], [[100, 100], [5, 5]]
    cha_t, cha_q = [[12, 18], [14, 20]], [[5, 5], [100, 100]]

However, the code somehow cuts the x-label on figure as below: wrong graph

I am pretty sure it is because of changing the figsize and seems that that it allocates label space proportionally to it. See the normal figsize figure below: right graph

How can I preserve enough space for xlabel with different figsizes? And is it actually supposed to be like this as it seems as a bug for me?

I would highly appreciate your advice!

CodePudding user response:

Use enter image description here

CodePudding user response:

Use enter image description here

  • Related