如何更改绘图图形大小

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

我使用 matplotlib 和 Plotly 制作了散点图。我希望高度、宽度和标记像 matplotlib 图中那样分散。请参阅附图。

我在 Plotly 中使用了以下代码

import plotly
import plotly.plotly as py
from plotly.graph_objs import Scatter
import plotly.graph_objs as go


trace1 = go.Scatter(
    x=x1_tsne,  # x-coordinates of trace
    y=y1_tsne,  # y-coordinates of trace
    mode="markers ",  # scatter mode (more in UG section 1)
    text=label3,
    opacity=1,
    textposition="top center",
    marker=dict(size=25, color=color_4, symbol=marker_list_2, line=dict(width=0.5)),
    textfont=dict(
        color="black",
        size=18,  # can change the size of font here
        family="Times New Roman",
    ),
)

layout = {
    "xaxis": {
        "showticklabels": False,
        "showgrid": False,
        "zeroline": False,
        "linecolor": "black",
        "linewidth": 2,
        "mirror": True,
        "autorange": False,
        "range": [-40, 40],
    },
    "yaxis": {
        "showticklabels": False,
        "showgrid": False,
        "zeroline": False,
        "linecolor": "black",
        "linewidth": 2,
        "mirror": True,
        "autorange": False,
        "range": [-40, 40],
    },
}

data = [trace1]

fig = go.Figure(data=data, layout=layout)

py.iplot(fig)

我尝试调整范围但没有帮助。此外,我使用了自动量程,但没有帮助。你能帮我解决这个问题吗?

我想要的图像为


编辑:这可以通过以下代码来完成。我正在问题中更新:

trace1 = go.Scatter(
    x=x1_tsne,  # x-coordinates of trace
    y=y1_tsne,  # y-coordinates of trace
    mode="markers +text ",  # scatter mode (more in UG section 1)
    text=label3,
    opacity=1,
    textposition="top center",
    marker=dict(size=25, color=color_4, symbol=marker_list_2, line=dict(width=0.5)),
    textfont=dict(
        color="black",
        size=18,  # can change the size of font here
        family="Times New Roman",
    ),
)
data = [trace1]

layout = go.Layout(
    autosize=False,
    width=1000,
    height=1000,
    xaxis=go.layout.XAxis(linecolor="black", linewidth=1, mirror=True),
    yaxis=go.layout.YAxis(linecolor="black", linewidth=1, mirror=True),
    margin=go.layout.Margin(l=50, r=50, b=100, t=100, pad=4),
)

fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename="size-margins")
python plotly plotly-python figure
1个回答
91
投票

你有没有考虑过使用

fig.update_layout(
    autosize=False,
    width=800,
    height=800,)

并最终减少您的

size
marker

更新

完整代码

import plotly.graph_objs as go

trace1 = go.Scatter(
    x=x1_tsne,           # x-coordinates of trace
    y=y1_tsne,          # y-coordinates of trace
    mode='markers +text ',   # scatter mode (more in UG section 1)
    text = label3,
    opacity = 1,
    textposition='top center',

    marker = dict(size = 12, color = color_4, symbol = marker_list_2, line=dict(width=0.5)),
     textfont=dict(
        color='black',
        size=18, #can change the size of font here
        family='Times New Roman'
     )

    )
data = [trace1]

layout = go.Layout(
    autosize=False,
    width=1000,
    height=1000,

    xaxis= go.layout.XAxis(linecolor = 'black',
                          linewidth = 1,
                          mirror = True),

    yaxis= go.layout.YAxis(linecolor = 'black',
                          linewidth = 1,
                          mirror = True),

    margin=go.layout.Margin(
        l=50,
        r=50,
        b=100,
        t=100,
        pad = 4
    )
)

fig = go.Figure(data=data, layout=layout)

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