如何绘制彩色几何形式并用列表中的字符串填充它们

How to plot colored geometric forms and populate them with string from lists

我有 3 个列表,其中包含一些字符串:

high = ['string1','string2','string3']
med = ['string4','string5','string6']
low = ['string7','string8','string9']

我想制作如下图:

它可以是任何几何形式,但我想将来自 3 个列表的字符串放入其中:

red form gets high list's strings
yellow form gets med list's strings
green form gets low list's string

如果有人可以帮助我,我不知道从哪里开始,我很感激

我是这样处理的:

我已经使用 Plotly Library shapes 创建矩形和文本作为轴上的点,您可以在 Seaborn 和 Matplotlib 上使用相同的方法。

您可以通过以下方式在图上创建文本标签:

fig.add_trace(go.Scatter( x=[0, 0, 0], 
                          y=[3, 0, -3],
                          text=["red form gets high list's strings",
                                "yellow form gets med list's strings",
                                "green form gets low list's string"], 
                          mode="text",
                          textfont=dict(color="black", size=18,family="Arail",)))

相应文本坐标的矩形形状可以创建如下:

fig.add_shape(type="rect",
    line_color="gray", fillcolor="red",
    x0= <Fixed x0 coordinate point>, 
y0= <desired y0 coordinate point>, x1= <Fixed x2 coordinate point>, y1=<Desired y1 coordinate point>)

此外,我更新了图形以隐藏轴和刻度

完整代码如下:

import plotly.graph_objects as go

fig = go.Figure()

# Creating scatter trace of text labels
fig.add_trace(go.Scatter( x=[0, 0, 0], 
                          y=[3, 0, -3],
                          text=["red form gets high list's strings",
                                "yellow form gets med list's strings",
                                "green form gets low list's string"], 
                          mode="text",
                          textfont=dict(color="black", size=18,family="Arail",)))

# Update axes properties
fig.update_xaxes(showticklabels=False,
                 showgrid=False, zeroline=False,)

fig.update_yaxes(showticklabels=False,
                 showgrid=False, zeroline=False,)

#x co-ordinate points
rect_x0, rect_x1 = -2, 2 


# Add rectangles
fig.add_shape(type="rect",
    line_color="gray", fillcolor="red",
    x0= rect_x0, y0=2, x1= rect_x1, y1=4)

fig.add_shape(type="rect",
    line_color="gray", fillcolor="green",
    x0= rect_x0, y0=-1, x1= rect_x1, y1=1)

fig.add_shape(type="rect",
    line_color="gray", fillcolor="yellow",
    x0= rect_x0, y0=-4, x1= rect_x1, y1=-2)

fig.update_shapes(opacity=0.3, xref="x", yref="y")

fig.update_layout(margin=dict(l=20, r=20, b=100),
                  height=600, width=800,
                  plot_bgcolor="white")

fig.show()

结果