我有一个图表,看起来像这样:

enter image description here

我想要对这个点的 colored颜色 组合进行排序,以实现类似于17开头的所有版本的一种 colored颜色 ,18和最后20个版本的不同 colored颜色 .我不知道我是否可以在情节中做到这一点,因为它非常具体,并且没有找到关于这方面的信息.还有没有可能为子版本添加不同的 colored颜色 ,例如17我们有不同的类别,如17.2.3,17.2.2等等.

以下是我的数据:

            Days Difference                commitDate   Year-Month
18538         1291           2021-01-25 11:15:48         2020-01
18539         1135             2020-11-30 05:11:41       2020-11
18540         1100            2020-08-17 07:22:54        2020-08
18541         900              2020-08-17 07:12:05       2020-01
18542         340              2020-01-09 06:21:03       2020-01
18543         203              2019-11-20 06:03:28       2019-11
18544         120             2019-11-15 02:50:28        2019-11

以下是我到目前为止编写的代码:

data1= final_api.query("info_title=='Avi CertificateManagementProfile Object API'")
data1['commitDate'] = pd.to_datetime(final_api['commitDate']) 
import plotly.graph_objects as go
fig = go.Figure()

fig.add_trace(go.Scatter(mode='lines',
                         x=data1["commitDate"],
                         y=data1["Days_difference"],
                         line_color='black',
                         line_width=1,
                         line_shape='vh',
                         showlegend=False
                       )
             )

fig.add_trace(go.Scatter(mode='markers',
                         x=data1["commitDate"],
                         y=data1["Days_difference"],
                         marker=dict(color=data1['day'], colorscale='plasma', size=10),
                         showlegend=False
                        )
             )

for _,row in data1.iterrows():
    fig.add_annotation(
        go.layout.Annotation(
            x=row["commitDate"],
            y=row["Days_difference"],
            text=row['info_version'],
            showarrow=False,
            align='center',
            yanchor='bottom',
            yshift=10,
            textangle=-90)
    )
fig.update_layout(template='plotly_white',title_text=' Version Change in Avi CertificateManagementProfile Object API over its Age',title_x=0.5,
                  xaxis_title='Year-Month', yaxis_title='Age of the API (in days)', xaxis_tickformat = '%d %B (%a)<br>%Y', height=700, width=1300)
fig.update_xaxes(showline=True, linewidth=1, linecolor='black', mirror=True)
fig.update_yaxes(showline=True, linewidth=1, linecolor='black', mirror=True)

fig.show()

任何帮助或指导都将不胜感激.

推荐答案

目前,您正在根据参数marker=dict(color=data1['day'], colorscale='plasma', size=10)中的'day'列分配标记 colored颜色 ,但听起来您似乎想要根据主要版本分配 colored颜色 .

您可以从INFO_VERSION列提取主版本,并将其存储在名为"major_version"的新列中:

data1['major_version'] = data1['info_version'].str.split('.').str.get(0)

然后,我建议使用px.scatter,这样可以更容易地将分类列作为 colored颜色 传递(请参阅文档here).

然后重新构造代码,首先绘制标记,然后绘制连接标记的线条:

import plotly.express as px

fig = px.scatter(data1, x='commitDate', y='Days_difference', color='major_version')

fig.add_trace(go.Scatter(mode='lines',
                         x=data1["commitDate"],
                         y=data1["Days_difference"],
                         line_color='black',
                         line_width=1,
                         line_shape='vh',
                         showlegend=False
                       )
             )

fig.update_layout(showlegend=False)

并保持其余代码不变.

Python相关问答推荐

需要计算60,000个坐标之间的距离

如何在polars(pythonapi)中解构嵌套 struct ?

如何使用数组的最小条目拆分数组

DataFrames与NaN的条件乘法

不允许访问非IPM文件夹

将scipy. sparse矩阵直接保存为常规txt文件

网格基于1.Y轴与2.x轴显示在matplotlib中

在代码执行后关闭ChromeDriver窗口

基于Scipy插值法的三次样条系数

为什么我的sundaram筛这么低效

无法在Spyder上的Pandas中将本地CSV转换为数据帧

Pandas在rame中在组内洗牌行,保持相对组的顺序不变,

如何在PythonPandas 中对同一个浮动列进行逐行划分?

.awk文件可以使用子进程执行吗?

时间戳上的SOAP头签名无效

如何通过特定导入在类中执行Python代码

将参数从另一个python脚本中传递给main(argv

如何在networkx图中提取和绘制直接邻居(以及邻居的邻居)?

将标量值作为输入并输出矩阵的函数的积分

如何在函数签名中输入数据类字段