我必須在同一個 PNG 檔案中保存兩個不同的散點圖。這是我一直在嘗試的代碼:
chartFileName = "gragh.png"
import matplotlib.pyplot as plt
x=data['Goals']
y=data['Shots pg']
slope, intercept, rvalue, pvalue, se = scipy.stats.linregress(x, y)
yHat = intercept slope * x
plt.plot(x, y, '.')
dataPlot=plt.plot(x, yHat, '-')
plt.xlabel("Goals", fontsize=14, labelpad=15)
plt.ylabel("Shots pg", fontsize=14, labelpad=15)
plt.show
plt.savefig(chartFileName)
x=data['Possession%']
y=data['Goals']
slope, intercept, rvalue, pvalue, se = scipy.stats.linregress(x, y)
yHat = intercept slope * x
plt.plot(x, y, '.')
plt.plot(x, yHat, '-')
plt.xlabel("Possession%", fontsize=14, labelpad=15)
plt.ylabel("Goals", fontsize=14, labelpad=15)
plt.show
plt.savefig(chartFileName)
如果我嘗試這個,它只是保存第二個情節,而不是他們兩個。
uj5u.com熱心網友回復:
subplot 能幫你。
chartFileName = "gragh.png"
fig = plt.figure()
ax1 = fig.add_subplot(2,1,1)
ax1.plot(x, y, '.')
ax1.set_xlabel("Goals", fontsize=14, labelpad=15)
ax1.set_ylabel("Shots pg", fontsize=14, labelpad=15)
ax2 = fig.add_subplot(2,1,2)
ax2.plot(x, yHat, '-')
ax2.set_xlabel("Possession%", fontsize=14, labelpad=15)
ax2.set_ylabel("Goals", fontsize=14, labelpad=15)
fig.savefig(chartFileName)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/383675.html
標籤:Python matplotlib 阴谋 数据科学 PNG
上一篇:matplotlib中沒有注釋
下一篇:基于行合并兩個資料幀
