简体   繁体   中英

Set coordinate origin plotly python

This is my code:

trace1 = go.Scatterpolar(
    r = r,
    theta = theta,
    mode='markers',
    marker=dict(
        size=12,
        color= iris.target,                
        opacity=1
        )
)

dc_1 = go.Scatterpolar( r = [0,V_r[0][0]],
                     theta = [0,V_r[0][1]],

                     marker = dict( size = 1,
                                    color = "rgb(84,48,5)"),
                     line = dict( color = "red",
                                width = 6),
                     name = "Var1"
                     )
dc_2 = go.Scatterpolar( r = [0,V_r[1][0]],
                   theta = [0,V_r[1][1]],

                   marker = dict( size = 1,
                                  color = "rgb(84,48,5)"),
                   line = dict( color = "green",
                                width = 6),
                   name = "Var2"
                 )
dc_3 = go.Scatterpolar( r = [0,V_r[2][0]],
                     theta = [0,V_r[2][1]],

                     marker = dict( size = 1,
                                  color = "rgb(84,48,5)"),
                     line = dict( color = "blue",
                                width = 6),
                     name = "Var3"
                 ) 
dc_4 = go.Scatterpolar( r = [0,V_r[3][0]],
                     theta = [0,V_r[3][1]],

                     marker = dict( size = 1,
                                  color = "rgb(84,48,5)"),
                     line = dict( color = "yellow",
                                width = 6),
                     name = "Var4"
                   )


data = [dc_1,dc_2,dc_3,dc_4, trace1]
layout = go.Layout( 
        xaxis=dict(
        title='PC1',
        rangemode='tozero',
        titlefont=dict(
           family='Courier New, monospace',
           size=18,
           color='#080707'
       )
   )
)
fig = go.Figure(data=data, layout=layout)
plot(fig, filename='Scatter polar, PCA.')

And this is the graph resultant:

enter image description here

As you can see, currently the lines of the variables start from "0", but the origin of coordinates is in r = - 5 (since that is the first value it receives) how can I set it to r = 0?

r has to be represented in absolute value, since the address gives you the value of theta. r cannot be < 0:

r = abs(np.squeeze(np.asarray(P[:,0])))
theta = (np.squeeze(np.asarray(P[:,1])))*(180/math.pi)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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