簡體   English   中英

我的 fig1.savefig 函數將我的圖形保存為空白屏幕,我該如何解決這個問題?

[英]My fig1.savefig function is saving my figure as a blank screen, how do I fix this?

我正在通過 .csv 文件導入數據並繪制它,但是當我繪制圖形並嘗試將其保存到我的谷歌驅動器時,它只會保存一個沒有任何數據的空白圖像。 我正在使用 Google Collaboratory。

這是我的代碼:

#Displaying the Data


import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

plt.title("Score of Each Raisan Thrown", fontsize ='x-large')

plt.ylabel("Valid Raisans Thrown", fontsize='large')
plt.xlabel("Score", fontsize= 'large')

dart = data[:,0]
score =  data[:,1]

plt.plot(score ,dart, marker='o', linestyle='none', color='black')

ax = plt.subplot()

ax.set_facecolor('seashell')

# Adding ticks to make my plot easier to understand/read

ax.set_yticks([20,40,60,80,100,120,140,160,180,200])
ax.set_xticks([-16,-14,-12,-10,-8,-6,-4,-2,0,2,4,6,8,10,12,14,-16])

fig = plt.figure(figsize=(10,5))

fig = plt.gcf()
plt.draw()
fig.savefig(datapath+'My Experiment1 Plot')

plt.show()


因為你的

fig = plt.figure(figsize=(10,5))

fig = plt.gcf()
plt.draw()
fig.savefig(datapath+'My Experiment1 Plot')

在所有繪圖命令之后出現,這意味着您正在創建一個新圖形而無需繪制任何內容並保存它。 您需要重新排列命令:

# get the data:
dart = data[:,0]
score =  data[:,1]

# set up the fig and axes:
fig, ax = plt.subplots(figsize=(10,5))

# plot the data
plt.plot(score ,dart, marker='o', linestyle='none', color='black')

# additional formatting
plt.title("Score of Each Raisan Thrown", fontsize ='x-large')
plt.ylabel("Valid Raisans Thrown", fontsize='large')
plt.xlabel("Score", fontsize= 'large')

# even more formatting
ax.set_facecolor('seashell')

# Adding ticks to make my plot easier to understand/read    
ax.set_yticks([20,40,60,80,100,120,140,160,180,200])
ax.set_xticks([-16,-14,-12,-10,-8,-6,-4,-2,0,2,4,6,8,10,12,14,-16])

fig.savefig(datapath+'My Experiment1 Plot')

plt.show()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM