我有一个巧妙地用三个子图表示facet_row图,这些子图工作得很好。我想在所有的行中添加一个框,这些行为情节的一个特定区域着色,并添加一个文本。add_vrect应该做这份工作,但我很难让它开始工作。
https://plotly.com/python/horizontal-vertical-shapes/ https://plotly.com/python/facet-plots/
下面工作的代码
import pandas as pd
import plotly.express as px
import plotly.io as pio
ftir_data_facet = pd.read_csv(r"C:\Users\mch047\Box Sync\PhD project Mikkel C\OneDrive - UiT Office 365\Mikkel_Christensen\Bioinformatics\Paper 1\Figure 2 Plate screen panel\Full_FTIR_dataset\Paper1_Figure2_FTIR_tidy_faceformat_071120.csv", sep=";")
#ftir_data_facet
figure2_facet = px.scatter(ftir_data_facet, x="Wavenumbers (1/cm)", y="Absorbance", color="Strain", facet_row="Plate")
figure2_facet.update_xaxes(title_text="Wavenumbers (1/cm)", range=[4000, 1000], showgrid=False)
fig.show()我试图补充如下:
figure2_facet.add_vrect(x0="1750", x1="1700", row=All,
annotation_text="Carbonyl region", annotation_position="top left",
fillcolor="green", opacity=0.25, line_width=0)我得到:
"AttributeError:‘图’对象没有属性'add_vrect'“
有人能帮我解释一下为什么不起作用吗?
发布于 2020-11-07 21:53:50
这似乎是一个版本问题。到2020年10月23日,add_vrect()似乎已经作为新功能和其他许多版本的4.12.0一起推出了:
已添加 引用一个维度中的绘图轴和另一个维度中的数据的形状可以使用新的add_hline、
add_vline、add_hrect、add_vrect函数添加,这些函数还支持row="all"和col="all"参数。(#2840)add_trace、add_shape、add_annotation、add_layout_image、add_hline、add_vline、add_hrect、add_vrect函数接受参数exclude_empty_subplots,如果为True,则只将对象添加到已经包含跟踪或布局对象的子图中。这对于row="all"和col="all"参数非常有用。
因此,我最初的建议是巧妙地更新,然后再试一次。
https://stackoverflow.com/questions/64728768
复制相似问题