在matplotlib图表上,我很难从y轴上删除科学符号。(如果我使用plt.yaxis.set\u major\u formatter(ScalarFormatter(usecoffset=False))我想显示变量中保存的原始str或float,我会得到一个属性aror:'matplotlib.pyplot'没有属性'yaxis'。 另外,plt.ticklabel_格式(usecoffset=False,style='plain')也不起任何作用(也没有错误)
from binance.client import Client
import time, os, csv, datetime
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib as mpl
from matplotlib.ticker import ScalarFormatter
client = Client(apikey, apisecret)
mpl.rcParams['toolbar'] = 'None'
fig = plt.figure(figsize=(4,3))
plt.style.use('ggplot')
plt.rcParams['ytick.right'] = plt.rcParams['ytick.labelright'] = True
plt.rcParams['ytick.left'] = plt.rcParams['ytick.labelleft'] = False
x_vars = []
y_vars = []
def animate(i):
global x_vars
global y_vars
if len(x_vars) > 30:
x_vars = x_vars[-30:]
y_vars = y_vars[-30:]
else:
pass
current_time = client.get_server_time()
current_price = client.get_symbol_ticker(symbol="XRPBTC")
trstime = current_time["serverTime"] / 1000
time = datetime.datetime.fromtimestamp(int(trstime)).strftime('%M:%S')
x_vars.append(str(time))
y_vars.append(float(current_price["price"]))
plt.cla()
plt.plot(x_vars, y_vars)
plt.xticks(rotation = 45)
ani = animation.FuncAnimation(fig, animate, interval=500)
plt.tight_layout()
plt.show()
好的,它现在可以工作了,只需在动画函数中插入plt.ticklabel_格式(style='plain',usecoffset=False,axis='y')
相关问题 更多 >
编程相关推荐