首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在python中获得背景图像?

如何在python中获得背景图像?
EN

Stack Overflow用户
提问于 2022-03-28 08:41:48
回答 1查看 91关注 0票数 0

我想有我的形象设置为背景,这幅画也涵盖标题和传说和轴,而不仅仅是在图像。

这在蟒蛇中是可能的吗?

就目前而言,我正在巧妙地使用绘图,但如果其他工具工作得更好,则可以使用其他工具。我可以更改fig.add_layout_image中的设置吗?

代码语言:javascript
运行
复制
import plotly.express as px
color_dict={'Djurgården': 'dodgerblue', 
            'Malmö FF': 'lightcyan',
            'Hammarby': 'lawngreen',
            'Sirius': 'darkblue',
            'AIK': 'black',
            'Elfsborg': 'goldenrod',
            'Norrkoping': 'lightblue',
            'Mjällby': 'lightgoldenrodyellow',
            'Varbergs BoIS': 'darkgreen',
            'Halmstad': 'mediumblue',
            'Degerfors': 'darkred',
            'Kalmar': 'indianred',
            'BK Häcken': 'yellow',
            'Östersunds FK': 'red',
            'Örebro SK': 'darkgray'
           }
fig = px.scatter(df2, x=statx, y=staty, color="Team",
                 size="MP", color_discrete_map=color_dict)

fig.add_annotation(text="Magnus Eriksson",
                  xref="paper", yref="paper",
                  x=0.16, y=1, showarrow=False, bgcolor="black", font=dict(
            
            color="white"
            ))

fig.add_annotation(text="Mohanad Jeahze",
                  xref="paper", yref="paper",
                  x=0.225, y=0.9, showarrow=False, bgcolor="black", font=dict(
            color="white"
            ))

fig.add_annotation(text="Darijan Bojanic",
                  xref="paper", yref="paper",
                  x=0.48, y=0.8, showarrow=False, bgcolor="black", font=dict(
            color="white"
            ))

fig.add_annotation(text="Moustafa Zeidan",
                  xref="paper", yref="paper",
                  x=0.55, y=0.6, showarrow=False, bgcolor="black", font=dict(
            color="white"
            ))

fig.add_annotation(text="Akinkunmi Amoo",
                  xref="paper", yref="paper",
                  x=0.8, y=0.55, showarrow=False, bgcolor="black", font=dict(
            color="white"
            ))

fig.add_annotation(text="Tashreeq Matthews",
                  xref="paper", yref="paper",
                  x=0.8, y=0.475, showarrow=False, bgcolor="black", font=dict(
            color="white"
            ))

fig.add_annotation(text="Edward Chilufya",
                  xref="paper", yref="paper",
                  x=0.82, y=0.375, showarrow=False, bgcolor="black", font=dict(
            color="white"
            ))

fig.add_annotation(text="Patrick Wålemark",
                  xref="paper", yref="paper",
                  x=0.975, y=0.32, showarrow=False, bgcolor="black", font=dict(
            color="white"))

fig.update_layout(
    #title="Allsvenskan 2021: xT Passing vs xT Dribble",
    title={
        'text': "Allsvenskan 2021: xT Passing vs xT Dribble",
        'y':0.95,
        'x':0.5,
        'xanchor': 'center',
        'yanchor': 'top'},
    xaxis_title="Normalized Value: xT Dribbles per 90",
    yaxis_title="Normalized Value: xT Passes per 90",
    legend_title="Teams Allsvenskan 2021",
)

img_width = 1
img_height = 1
scale_factor = 2.5

fig.add_layout_image(
    dict(
        sizex=img_width * scale_factor,
        y=img_height * scale_factor,
        sizey=img_height * scale_factor,
        xref="x",
        yref="y",
        opacity=1.0,
        layer="below",
        sizing="stretch",
        source="LJUS_BG_Playmaker.png")
)
fig.show()
´´´
EN

回答 1

Stack Overflow用户

发布于 2022-03-28 08:46:35

尝尝这个。

代码语言:javascript
运行
复制
backgroundImage = PhotoImage("D:\Documents\example.png")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71644599

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档