1

May I ask how do i adjust the size of the graph? This is my code.

import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot(mean, median, marker="s", linestyle="")
for i, txt in enumerate(words):
    ax.annotate(txt, (mean[i],median[i]))
ax.set_xlabel("median")
ax.set_ylabel("mean")

plt.show()

I tried to use

fig,ax=plt.subplots(figsize=(20,10))

but failed.

pppp
  • 11
  • 1

2 Answers2

0

You first must have code that can execute, prior to tweaking the size of a figure:

(I added dummy data, and now it works)

import matplotlib.pyplot as plt

if __name__ == '__main__':

    fig = plt.figure()
    ax = fig.add_subplot(111)

    mean, median = [1, 2, 3], [4, 5, 6]   # dummy data

    ax.plot(mean, median, marker="s", linestyle="")

    for i, txt in enumerate(['a', 'b', 'c']):
        ax.annotate(txt, (mean[i], median[i]))

    ax.set_xlabel("median")
    ax.set_ylabel("mean")

    fig, ax = plt.subplots(figsize=(10, 10))   # size in inches

    plt.show()
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80
0

you can basically do this:

from pylab import rcParams
rcParams[figure.figsize] = (5,4) # Size in inches

Then you may continue with your code :)

TheSHETTY-Paradise
  • 1,024
  • 2
  • 9
  • 19