[英]Plotly: How to adjust annotation text angle for rectangles using `add_vrect()`?
[英]Plotly: Problem with plotly express add_vrect to figure
我有一個帶有三個子圖的情節表達 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:‘Figure’對象沒有屬性‘add_vrect’”
任何人都可以幫助或解釋為什么它不起作用..?
這個好像是版本問題。 add_vrect()
似乎已被引入作為一個新functinality在版本相當多的人相處4.12.0
截至2020年10月23日:
添加
可以使用新的 add_hline、
add_vline
、add_hrect
、add_vrect
函數添加引用一個維度中的繪圖軸和另一個維度中的數據的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"
參數結合使用很有用。
所以我最初的建議是更新情節並重試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.