python - 如何更改绘图图形大小

标签 python plotly plotly-python figure

enter image description here我使用 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][![enter image description here][1]][1] 
        
    },
    '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)

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

我想要的图像为 enter image description here

##update:这可以通过以下代码来完成。我正在问题中更新这一点:

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') 

最佳答案

您是否考虑过使用

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

并最终减小标记大小

更新

完整代码

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)

关于python - 如何更改绘图图形大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59953431/

相关文章:

python - 如何在 python 2.7 中为 TLS 套接字进行证书固定?

python - 在热图中绘制不必要的空间

python - 如何使用 Python Etsy HTTP API 方法添加新项目?

python - 调用类变量时打印消息

python - 函数显示错误

python - 如何将包含相同参数子集且值相同的 2 个函数合并为 1 个函数?

python - python plotly : PlotlyError

python - 在条形图上的 Plotly Express 中更改轴/图例名称

python - plotly:如何向现有图形添加文本?

python - 大小为 0 的标记在 Plotly Express 散点图中不可见