我的一位朋友最近继承了一台旧笔记本电脑,刚刚安装了Windows 7,并希望延长电池续航时间.最初电池持续约20分钟,但通过手动让电池完全放电再充电几次,他已设法将电池寿命延长到一个小时左右.我们认为看到我们可以提高电池性能的程度会很有趣!我想写一个脚本让电池在一夜之间循环 - 这对于偶尔在任何一台电脑上运行来维持电池健康状况可能会有用吗?我可以获得电池状态,但无法看到如何指示笔记本电脑忽略交流电源线的存在并使用电池.我有一种感觉答案就在那里:https: //pypi.python.org/pypi/LaptopControlPanel但我对我的理解完全达到极限!任何帮助都会很棒.
import ctypes
from ctypes import wintypes
class SYSTEM_POWER_STATUS(ctypes.Structure):
_fields_ = [
('ExternalPower', wintypes.BYTE),
('BatteryFlag', wintypes.BYTE),
('BatteryLifePercent', wintypes.BYTE),
('Reserved1', wintypes.BYTE),
('BatteryLifeTime', wintypes.DWORD)
]
SYSTEM_POWER_STATUS_P = ctypes.POINTER(SYSTEM_POWER_STATUS)
GetSystemPowerStatus = ctypes.windll.kernel32.GetSystemPowerStatus
GetSystemPowerStatus.argtypes = [SYSTEM_POWER_STATUS_P]
GetSystemPowerStatus.restype = wintypes.BOOL
status = SYSTEM_POWER_STATUS()
if not GetSystemPowerStatus(ctypes.pointer(status)):
raise cytpes.WinError()
print 'ExternalPower', status.ExternalPower
#print 'BatteryFlag', status.BatteryFlag
print 'BatteryLifePercent', status.BatteryLifePercent
print 'BatteryLifeTime', status.BatteryLifeTime
if status.ExternalPower == True and status.BatteryLifePercent == 100:
print 'Connected to mains and at 100% charge: Begining decharge' …Run Code Online (Sandbox Code Playgroud) 我想绘制数组的多列,并在绘图图例中将它们标记为相同。但是在使用时:
x = np.loadtxt('example_array.npy')
plt.plot(x[:,1:3],label = 'first 2 lines')
plt.plot(x[:,3:5],label = '3rd and 4th lines')
plt.legend()
Run Code Online (Sandbox Code Playgroud)
我得到的图例标签和我的线条一样多。所以上面的代码在图例框中产生了四个标签。
一定有一种简单的方法可以为一组行分配标签吗?!但是我找不到它...
我想避免不得不求助于
x = np.loadtxt('example_array.npy')
plt.plot(x[:,1],label = 'first 2 lines')
plt.plot(x[:,1:3])
plt.plot(x[:,3],label = '3rd and 4th lines')
plt.plot(x[:,3:5])
plt.legend()
Run Code Online (Sandbox Code Playgroud)
提前致谢