为什么要创建两个图? 我希望不要只创建两个图,而只能创建一个图。
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()
答案 0 :(得分:1)
这给了我一个。我更改了您要求绘图的线的位置。调用pl.figure和其他一些使您的绘图漂亮的参数后,请调用pl.plot。
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()
答案 1 :(得分:1)
调用pl.plot时创建第一个图形,调用pl.figure函数时创建第二个图形。
您需要将其中之一扔掉。
答案 2 :(得分:0)
如果在调用plt.plot后使用plt.figure,则会创建第二个数字
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()