繁体   English   中英

Plotly:如何更改图形大小?

[英]Plotly: How to change figure size?

在此处输入图片说明 我使用 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)

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

我希望图像为在此处输入图片说明

##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,)

并最终减小markersize

更新

完整代码

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM