将不同数据集的虚线添加到现有绘图中

问题描述 投票:0回答:1

我已经得到了该数据集,我用它来绘制浓度与一些生长测量值的关系图。但是,现在我想添加一条带有另一个数据集的值的虚线。当我打印该值时,它打印出 0.25,这正是我想要的,但在绘图上,该线显示在我的浓度 0.03 之后和 0.06 之前。我觉得我的虚线没有考虑浓度值。有解释吗?

df_filtered['CONC'] = pd.to_numeric(df_filtered['CONC'], errors='coerce')
df_filtered = df_filtered.dropna(subset=['CONC'])

df_filtered = df_filtered[df_filtered['CFZ_BINARY_PHENOTYPE'].isin(['S', 'R'])]

colors = {'S': 'red', 'R': 'blue'}

sns.boxplot(data=df_filtered, x='CONC', y='growth_in_pixels', hue='CFZ_BINARY_PHENOTYPE', palette=colors)

plt.xlabel('Concentration')
plt.ylabel('Growth in Pixels')
plt.title('Boxplot of Growth in Pixels for CFZ')

plt.xticks(rotation=45)

# Add ECOFF line for CFZ

ecoff_value_cfz = df_ECOFF.loc[df_ECOFF['DRUG_ID'] == 'CFZ', 'ECOFF'].values[0]
print(ecoff_value_cfz)

plt.axvline(x=ecoff_value_cfz, color='red', linestyle='--', label=f"ECOFF (CFZ): {ecoff_value_cfz}")

To see the plot

python matplotlib plot
1个回答
0
投票

做这样的事情怎么样:

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

data = {
    'CONC': [0.01, 0.02, 0.03, 0.03, 0.06, 0.06, 0.06, 0.25, 0.25],
    'growth_in_pixels': [20, 30, 40, 50, 60, 70, 80, 90, 100],
    'CFZ_BINARY_PHENOTYPE': ['S', 'S', 'R', 'R', 'S', 'S', 'R', 'R', 'S']
}
df_filtered = pd.DataFrame(data)

ecoff_data = {
    'DRUG_ID': ['CFZ', 'Another'],
    'ECOFF': [0.25, 0.5]
}
df_ECOFF = pd.DataFrame(ecoff_data)


df_filtered['CONC'] = pd.to_numeric(df_filtered['CONC'], errors='coerce')
df_filtered = df_filtered.dropna(subset=['CONC'])
df_filtered = df_filtered[df_filtered['CFZ_BINARY_PHENOTYPE'].isin(['S', 'R'])]

colors = {'S': 'red', 'R': 'blue'}
sns.boxplot(data=df_filtered, x='CONC', y='growth_in_pixels', hue='CFZ_BINARY_PHENOTYPE', palette=colors)

plt.xlabel('Concentration')
plt.ylabel('Growth in Pixels')
plt.title('Boxplot of Growth in Pixels for CFZ')
plt.xticks(rotation=45)

ecoff_value_cfz = df_ECOFF.loc[df_ECOFF['DRUG_ID'] == 'CFZ', 'ECOFF'].values[0] 

unique_concs = sorted(df_filtered['CONC'].unique())
position = unique_concs.index(ecoff_value_cfz)  

plt.axvline(x=position, color='red', linestyle='--', label=f"ECOFF (CFZ): {ecoff_value_cfz}")
plt.legend()

plt.show()

这给出了

© www.soinside.com 2019 - 2024. All rights reserved.