python - Plotly:如何更改图形大小?
问题描述
我使用 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)
我尝试调整范围但没有帮助。另外,我使用了没有帮助的自动量程。你能帮我解决这个问题吗?
##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,)
并最终减少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)
推荐阅读
- python - 如何在 Colab 中将长 DEAP 日志(10 MM)转换为数据帧时修复 RAM 限制?
- javascript - iOS 键盘未关闭,由 iframe 中的输入触发
- ios - 如何从xml解析字符串ios中删除或替换垃圾值或无效值&?
- r - 计算 R 中的所有列
- vba - 如何删除地址?
- node.js - Express cookie 在浏览器中不可见
- xaml - 如何仅为背景(而不是标签)设置透明度?
- node.js - 如何使用 Node.js 创建虚拟打印机
- bash - 从本地 .bat 脚本运行远程 .sh 脚本
- python - 如果我放一个像 s=1234567891 这样的字符串,代码可以工作,但是如果我有一个文本文件“yesno.txt”,其中有数据,则会出错