情节中的窃听器?轴限制的意外行为

2024-06-25 22:34:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我在jupyter笔记本里遇到了一个奇怪的行为bqplot。是我做错了什么,还是这可能是个错误?如果我首先为线性比例提供一个minmax参数,那么一切都正常。你知道吗

import numpy as np
import bqplot as bq

marks = []
# If e.g. bq.LinearScale(min=0, max=1) is used, everything works fine
scale_y = bq.LinearScale()
scale_x = bq.LinearScale()

ax_y = bq.Axis(scale=scale_x, orientation='vertical', label='Recovery (%)')
ax_x = bq.Axis(scale=scale_y, orientation='horizontal', label='Time (h)')

x = [0]
y = [0]
line_1 = bq.Lines(x=x, y=y,
                  scales={'x': scale_x, 'y': scale_y},
                  labels=['Test'])
fig = bq.Figure(marks=[line_1], axes=[ax_x, ax_y], title='API Example', legend_location='bottom-right')

fig

它返回:

enter image description here

稍后,我将附加一些数据:

x = np.linspace(0, 10)
y = x**2
line_2 = bq.Lines(x=x, y=y,
                  scales={'x': scale_x, 'y': scale_y},
                  labels=['Test'])
fig.marks = [line_2]

enter image description here

为什么x轴限制设置为100?应该是10。你知道吗

有可能改变轴的极限行为是奇怪的。似乎轴心被某种方式改变了。我可以改变x轴的极限,结果是y轴改变了。而且,情节还是错误的:

scale_y.min = 0
scale_y.max = 100

scale_x.min = 0
scale_x.max = 10

Tags: importas错误nplinefigaxmin