到目前为止,我已经花了几个小时来完成图9中的轴缩放。到目前为止,我发现的所有东西都不起作用。
是数据,还是定义图形的代码,希望你们中的任何人都能看到哪里出了问题。
数据如下所示:

数据类型包括:
concat object
direction object
date_trunc timedelta64[ns]
comment object
timestamp datetime64[ns]
dtype: object下面的代码按照预期创建了一个图形:
ch_time_plot = (p9.ggplot(data= ch_time,
mapping= p9.aes(x= 'timestamp',
y= 'date_trunc',
color= 'direction'))
+ p9.geom_line()
+ p9.theme(axis_text_x= p9.element_text(rotation=90))
)
# ch_time_plot += p9.ylim(0,5)
# => TypeError: Discrete value supplied to continuous scale
# ch_time_plot += p9.expand_limits(y=0)
# => AttributeError: 'int' object has no attribute 'value'
# ch_time_plot += p9.scale_y_continuous(limits = (1, 10))
# => TypeError: Discrete value supplied to continuous scale
ch_time_plot我想要实现的是始终显示y轴(0)的原点。一旦我注释掉代码中显示的一行代码(它应该这样做),我就会得到一条错误消息,并且没有更多的图形。
我的代码出了什么问题?
发布于 2021-10-19 09:58:18
由于所使用的数据类型,上例中的缩放不起作用。
只要在y轴上使用timedelta64[ns],缩放就不起作用。
经过以下转换后:
ch_time['change_time']= ch_time['date_trunc'] / np.timedelta64(1, 's')该图可以通过以下方式进行适当缩放:
ch_time_plot = (p9.ggplot(data= ch_time,
mapping= p9.aes(x= 'timestamp',
y= 'change_time',
color= 'direction'))
+ p9.geom_line()
+ p9.theme(axis_text_x= p9.element_text(rotation=90))
+ p9.scale_y_continuous(limits=(0, 6))
)https://stackoverflow.com/questions/69581385
复制相似问题