我长期以来一直使用小子程序来格式化我正在绘制的图表的轴。几个例子:
def format_y_label_thousands(): # format y-axis tick labels formats
ax = plt.gca()
label_format = '{:,.0f}'
ax.set_yticklabels([label_format.format(x) for x in ax.get_yticks().tolist()])
def format_y_label_percent(): # format y-axis tick labels formats
ax = plt.gca()
label_format = '{:.1%}'
ax.set_yticklabels([label_format.format(x) for x in ax.get_yticks().tolist()])
Run Code Online (Sandbox Code Playgroud)
但是,在昨天更新 matplotlib 后,我在调用这两个函数中的任何一个时收到以下警告:
UserWarning: FixedFormatter should only be used together with FixedLocator
ax.set_yticklabels([label_format.format(x) for x in ax.get_yticks().tolist()])
Run Code Online (Sandbox Code Playgroud)
出现这种警告的原因是什么?我无法弄清楚查看 matplotlib 的文档。
编辑:我找到了有关错误消息的解决方案 - 这是 IB 的 API 上的错误。我在下面作为答案显示的代码对于那些正在寻找从他们在 IB 的账户中读取头寸和资产净值的干净解决方案的人来说应该很有用。
最初的问题[见下面的解决方案; 在此处留下原始问题以获取上下文]:我正在尝试使用公司的 API 获取我在盈透证券 [IB] 的所有账户头寸。他们的文档虽然广泛,但非常令人困惑。示例代码充满了不必要的命令——我想要一些非常精简的东西。
我需要帮助:
到目前为止的代码:
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.common import * #for TickerId type
import pandas as pd
class ib_class(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
self.all_positions = pd.DataFrame([], columns = ['Account','Symbol', 'Quantity', 'Average Cost'])
def position(self, account, contract, pos, avgCost):
index = str(account)+str(contract.symbol)
self.all_positions.loc[index]=account,contract.symbol,pos,avgCost
def error(self, reqId:TickerId, errorCode:int, errorString:str):
if reqId > -1:
print("Error. Id: " …Run Code Online (Sandbox Code Playgroud)