0

我想绘制由一系列质量和强度给出的光谱。对于每一对我想绘制一条细线。当我放大时,线条的宽度不应该改变。条形图几乎可以满足我的需要。

import plotly.graph_objects as go 

fig = go.Figure(data=[go.Bar(
    x=df['mz_array'],
    y=df['intensity'],
    width = 1
)])

fig.show()

但是,当我放大条形时会改变它们的宽度。

4

1 回答 1

0

我修改了数据框,然后用来px.line绘制频谱:

def plot_spectrum(df, annot_threshold=1e4, threshold=0):

    df = df[df.intensity > threshold].reset_index()

    df1 = df.copy()
    df1['Text'] = df1.mz_array.astype(str)
    df1.loc[df1.intensity < annot_threshold, 'Text'] = None
    df1.Text.notnull().sum()

    df2 = df.copy()
    df2['intensity'] = 0
    
    df3 = pd.concat([df1, df2]).sort_values(['index', 'intensity'])
    
    fig = px.line(df3, x='mz_array', y='intensity', color='index', text='Text')
    fig.update_layout(showlegend=False)
    fig.update_traces(line=dict(width=1, color='grey'))
    fig.update_traces(textposition='top center')
    return fig

在此处输入图像描述

于 2020-07-26T23:00:30.453 回答