2

Why are two graphs created? I would like that instead of being created two separate graphs, only one was created.

import matplotlib.pyplot as pl

x=1,2,3,4
y=3,6,1,9
pl.plot(x, y)

pl.figure(figsize=(7.5, 5), dpi=80)
pl.axis([0,29,0,21])
pl.xticks([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]) 
pl.yticks([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20])
pl.xlabel("Giornate", fontweight="bold")
pl.ylabel("Ore", fontweight="bold")
pl.title("Febbraio 2019", fontsize=20, fontweight="bold")
pl.grid(b=True, color="gray")
pl.rcParams['axes.facecolor'] = "tan"

pl.show()
1
  • 1
    pl.figure(figsize=(7.5, 5), dpi=80) creates a new figure but you already called the plot command. Call pl.figure before you plot anything Commented Feb 1, 2019 at 15:32

3 Answers 3

1

First figure gets created when you call pl.plot and the second one gets created when you call pl.figure function.

You need to throw one of them out.

Sign up to request clarification or add additional context in comments.

Comments

1

You just need to change the position; where you call pl.plot as following:

import matplotlib.pyplot as pl
x=1,2,3, 4
y=3,6,1,9
pl.figure(figsize=(7.5, 5), dpi=80)
pl.axis([0,29,0,21])
pl.xticks([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]) 
pl.yticks([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20])
pl.plot(x, y)
pl.xlabel("Giornate", fontweight="bold")
pl.ylabel("Ore", fontweight="bold")
pl.title("Febbraio 2019", fontsize=20, fontweight="bold")
pl.grid(b=True, color="gray")
pl.rcParams['axes.facecolor'] = "tan" 
pl.show()

Comments

0

If you use plt.figure after calling plt.plot a second figure is created

import matplotlib.pyplot as pl

x=1,2,3,4
y=3,6,1,9


pl.figure(figsize=(7.5, 5), dpi=80)

pl.plot(x, y)

pl.axis([0,29,0,21])
pl.xticks([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]) 
pl.yticks([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20])
pl.xlabel("Giornate", fontweight="bold")
pl.ylabel("Ore", fontweight="bold")
pl.title("Febbraio 2019", fontsize=20, fontweight="bold")
pl.grid(b=True, color="gray")
pl.rcParams['axes.facecolor'] = "tan"

pl.show()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.