I have made a scatter plot using matplotlib and Plotly. I want the height, width and the markers to be scatter as in matplotlib plot. Please see the attached plots.
I used the following code in Plotly
JavaScript
x
57
57
1
import plotly
2
import plotly.plotly as py
3
from plotly.graph_objs import Scatter
4
import plotly.graph_objs as go
5
6
7
trace1 = go.Scatter(
8
x=x1_tsne, # x-coordinates of trace
9
y=y1_tsne, # y-coordinates of trace
10
mode='markers ', # scatter mode (more in UG section 1)
11
text = label3,
12
opacity = 1,
13
textposition='top center',
14
marker = dict(size = 25, color = color_4, symbol = marker_list_2, line=dict(width=0.5)),
15
textfont=dict(
16
color='black',
17
size=18, #can change the size of font here
18
family='Times New Roman'
19
)
20
21
)
22
23
layout = {
24
'xaxis': {
25
'showticklabels': False,
26
'showgrid': False,
27
'zeroline': False,
28
'linecolor':'black',
29
'linewidth':2,
30
'mirror':True,
31
'autorange':False,
32
'range':[-40, 40][![enter image description here][1]][1]
33
34
},
35
'yaxis': {
36
'showticklabels': False,
37
'showgrid': False,
38
'zeroline': False,
39
'linecolor':'black',
40
'linewidth':2,
41
'mirror':True,
42
'autorange':False,
43
'range':[-40, 40]
44
45
}
46
47
48
49
}
50
data = [trace1]
51
52
fig = go.Figure(
53
data= data,
54
layout= layout)
55
56
py.iplot(fig)
57
I try to tune the range but did not help. In addition, I use Autorange that did not help. Could you please help me with this.
##update: This can be done by the following code. I am updating this in the question:
JavaScript
1
43
43
1
trace1 = go.Scatter(
2
x=x1_tsne, # x-coordinates of trace
3
y=y1_tsne, # y-coordinates of trace
4
mode='markers +text ', # scatter mode (more in UG section 1)
5
text = label3,
6
opacity = 1,
7
textposition='top center',
8
9
marker = dict(size = 25, color = color_4, symbol = marker_list_2, line=dict(width=0.5)),
10
textfont=dict(
11
color='black',
12
size=18, #can change the size of font here
13
family='Times New Roman'
14
)
15
16
)
17
data = [trace1]
18
19
layout = go.Layout(
20
autosize=False,
21
width=1000,
22
height=1000,
23
24
xaxis= go.layout.XAxis(linecolor = 'black',
25
linewidth = 1,
26
mirror = True),
27
28
yaxis= go.layout.YAxis(linecolor = 'black',
29
linewidth = 1,
30
mirror = True),
31
32
margin=go.layout.Margin(
33
l=50,
34
r=50,
35
b=100,
36
t=100,
37
pad = 4
38
)
39
)
40
41
fig = go.Figure(data=data, layout=layout)
42
py.iplot(fig, filename='size-margins')
43
Advertisement
Answer
Have you considered to use
JavaScript
1
5
1
fig.update_layout(
2
autosize=False,
3
width=800,
4
height=800,)
5
and eventually reduce the size
of your marker
?
UPDATE
Full Code
JavaScript
1
45
45
1
import plotly.graph_objs as go
2
3
trace1 = go.Scatter(
4
x=x1_tsne, # x-coordinates of trace
5
y=y1_tsne, # y-coordinates of trace
6
mode='markers +text ', # scatter mode (more in UG section 1)
7
text = label3,
8
opacity = 1,
9
textposition='top center',
10
11
marker = dict(size = 12, color = color_4, symbol = marker_list_2, line=dict(width=0.5)),
12
textfont=dict(
13
color='black',
14
size=18, #can change the size of font here
15
family='Times New Roman'
16
)
17
18
)
19
data = [trace1]
20
21
layout = go.Layout(
22
autosize=False,
23
width=1000,
24
height=1000,
25
26
xaxis= go.layout.XAxis(linecolor = 'black',
27
linewidth = 1,
28
mirror = True),
29
30
yaxis= go.layout.YAxis(linecolor = 'black',
31
linewidth = 1,
32
mirror = True),
33
34
margin=go.layout.Margin(
35
l=50,
36
r=50,
37
b=100,
38
t=100,
39
pad = 4
40
)
41
)
42
43
fig = go.Figure(data=data, layout=layout)
44
45