python - 空散景图
问题描述
我正在尝试使用散景从我的 DataFrame 中绘制数据,并且绘图始终为空。下面是我的功能。
def statplot(stats_df,plotname):
try:
source_df = ColumnDataSource(data=stats_df.sort_values(by=['log_time']))
print(source_df.data)
output_file(plotname,'General Statistics')
datetime_tick_formats = {
key: ["%a %b %d %H:%M:%S"]
for key in ("seconds", "minsec", "minutes", "hourmin", "hours", "days")}
hover1 = HoverTool(tooltips=[('Date','@log_time{%Y-%m-%d %H:%M:%S}'),('Value','@PrivateMem')],formatters = {'@log_time':'datetime'})
p1 = figure(title="PrivateMemory MB",plot_width=800, plot_height=400,x_axis_type="datetime")
p1.xaxis.axis_label="Time"
p1.yaxis.axis_label="MB"
p1.xaxis.formatter = DatetimeTickFormatter(**datetime_tick_formats)
p1.line(x='log_time',y='PrivateMem',source=source_df,line_width=2,color="red",legend_label='Private Memory')
p1.add_tools(hover1)
plot = gridplot([p1],ncols=1)
save(plot)
我有 print source.data 来验证我的 ColumnDataSource 是否有任何值,并且看起来确实如此。下面是样本数据
{'index': array([ 550, 551, 552, ..., 1658, 1659, 1660]), 'log_time': array(['2021-02-19T17:08:27.000000000', '2021-02-19T17:10:59.000000000',
'2021-02-19T17:11:59.000000000', ...,
'2021-02-24T08:33:38.000000000', '2021-02-24T08:34:38.000000000',
'2021-02-24T08:35:38.000000000'], dtype='datetime64[ns]'), 'PrivateMem': array([' 33', ' 67', ' 72', ..., ' 91', ' 90', ' 90'], dtype=object), 'PagedMem': array([' 33', ' 67', ' 72', ..., ' 91', ' 90', ' 90'], dtype=object), 'ThreadCount': array([' 36', ' 54', ' 49', ..., ' 44', ' 45', ' 45'], dtype=object), 'HandleCnt': array([' 1134', ' 2214', ' 2232', ..., ' 2498', ' 2488', ' 2498'],
dtype=object)}
任何想法我在阻止绘制值的功能上做错了什么?
解决方案
问题在于 df 中带有空格的值。一旦我们删除了值中的空间,Bokeh 就可以毫无问题地绘制。
推荐阅读
- python - AttributeError:“NoneType”对象在尝试添加多个 keras 密集层时没有属性“_inbound_nodes”
- javascript - 在另一个文件中使用 Ajax 获取动态 PHP 表单 ID
- javascript - AngularJS - 在浏览器关闭之前使用 $window.onbeforeunload 调用 API
- python - django"
我一直在努力解决我认为是我的愚蠢疏忽的事情。我有一个表单,它将输入提供给一个视图,该视图查询我拥有的一些 SQL 表并返回一个列表,其中包含每个表中的列**。
正在发生的奇怪的事情是我的列表出现在
<QuerySet{[ ]}>
每个列表对象的括号。谁能告
- curl - 设置变量等于范围内的模式匹配
- android - java.lang.IllegalStateException:应为 BEGIN_OBJECT 但在第 2 行第 1 列错误为 STRING
- bash - 在 Bash 中:grep 命令输出未存储在文件中,并将其存储在文件中?
- scipy - 简单的 scipy curve_fit 测试未返回预期结果
- javascript - 如何在项目数组中选择一个按钮并取消选择前一个值
- python - SQLAlchemy 的“post_update”与已从会话中删除的对象的行为不同