帖子Plotly:在折线图中最后一个值处注释标记 显示了如何使用文本和单个标记注释行尾。但是,如何对多行执行相同的操作,同时设置关联的文本和标记以匹配所有行的颜色?
# imports
import pandas as pd
import plotly.express as px
# data
df = px.data.stocks()
colors = px.colors.qualitative.T10
# plotly
fig = px.line(df,
x = 'date',
y = [c for c in df.columns if c != 'date'],
template = 'plotly_dark',
color_discrete_sequence = colors,
title = 'Stocks',
)
fig.show()
Run Code Online (Sandbox Code Playgroud) 我有这样的数据
import pandas as pd
df = pd.DataFrame(
dict(
week=[1, 1, 2, 2, 3, 3] * 2,
layout=["classic", "classic", "modern", "modern"] * 3,
response=["conversion", "exit"] * 6,
cnt=[26, 23, 45, 34, 55, 44, 53, 27, 28, 25, 30, 34],))
Run Code Online (Sandbox Code Playgroud)
我不能使用两个类别的主要问题。我的代码:
px.bar(
data_frame=df,
x='week',
y='cnt',
template='plotly_dark',
color = 'layout'
)
Run Code Online (Sandbox Code Playgroud)
但我无法像 excel 示例中那样显示有关“响应”的信息
我有以下结构
struct node{
int value;
struct node *next;
struct node *prev;
};
Run Code Online (Sandbox Code Playgroud)
而且我认为大小必须大于sizeof(整数).
但是如何计算这个结构的整体大小令人困惑.
那么如何计算尺寸呢?
我的意思是我想手动计算,而不是通过计算机...
我有以下数据框架
> S
Source: local data frame [1,991 x 3]
Groups: exp
exp year commval
1 alb 1995 186
2 alb 1997 232
3 alb 1998 244
4 alb 2000 251
5 alb 1996 275
6 alb 1999 290
7 alb 2001 313
8 alb 2002 358
9 alb 2003 471
10 alb 2004 608
.. ... ... ...
Run Code Online (Sandbox Code Playgroud)
我想过滤年份== 1995而不是重新订购:
> S %>% filter(year == 1995) %>% arrange(commval)
Source: local data frame [130 x 3]
Groups: exp
exp year …Run Code Online (Sandbox Code Playgroud) 我使用 scikit-learn 通过 k-means 进行聚类:
from sklearn import cluster
k = 4
kmeans = cluster.KMeans(n_clusters=k)
Run Code Online (Sandbox Code Playgroud)
但另一个问题是:如何使用 scikit 学习计算 k 均值特征重要性?
挑战
当前者是元组时,我如何从(255, 255, 255, 0)到 '(255, 255, 255, 0)'?
细节:
我正在使用此处描述的方法将十六进制颜色转换为 rgba 颜色。我这样做是为了使用颜色作为带有不透明度元素的参数,如下所示:
color = 'rgba(255, 255, 255, 0)'
Run Code Online (Sandbox Code Playgroud)
您可能已经猜到了,参数必须是一个string类型。我已经把整数放在像这样的元组中
(255, 255, 255, 0)
Run Code Online (Sandbox Code Playgroud)
现在我需要将整个元组括在一个字符串中,就像'(255, 255, 255, 0)'进入我的最后一步:
'rgba(255, 255, 255, 0)'
Run Code Online (Sandbox Code Playgroud)
恐怕我在这里遗漏了一些明显且非常基本的 Python 元素,但是任何建议都会很棒!
对于像 的列表['A', 'B', 'C'],我试图构建或找到一个函数,该函数将在每次调用时返回列表的下一个元素。在这种情况下,如果它被调用超过 3 次,A则将被返回。在那之后B等等。
我有一个['A', 'B', 'C']要应用于不同对象的颜色列表。每次运行代码时,对象的数量可能会有所不同。如果列表中的对象多于颜色,我希望第四个对象具有 color 'A'。所以,正如标题所说,我想遍历一个列表 by 和 index 并从头开始 if index > len(list)。以下自定义函数looper将做到这一点。
def looper(lst, runs):
j = 0
for i in range(0, (len(lst)+(runs-(len(lst))))):
if i < len(lst):
print(lst[i])
else:
print(lst[j])
j +=1
Run Code Online (Sandbox Code Playgroud)
# input:
runs = 2
looper(['A', 'B', 'C'], runs)
# output:
A
B
Run Code Online (Sandbox Code Playgroud)
#input :
runs = 5
looper(['A', 'B', 'C'], runs)
#output …Run Code Online (Sandbox Code Playgroud)