我试图在情节上绘制一些NFL球队,但是每当我一直试图对某些球队进行注释时,文字就会移到情节的角落,而我无法靠近实际数据点。 / p>
参考:https://plot.ly/python/text-and-annotations/#styling-and-coloring-annotations
我已经尝试了超过半小时的时间来更改x和y值,无论我什么时候都将盒子移到绘图的角落,并且 我无法在美国地图内找到它。
问:如何用箭头符号注释蓝色数据点?
第二季:如何解决“用户警告:考虑改用IPython.display.IFrame”
这是我的代码和情节:
import pandas as pd
import numpy as np
from IPython.display import IFrame
import plotly.plotly as py
%matplotlib inline
df = pd.DataFrame({'latitude': [42.7,25.9,42.1,40.8],
'longitude': [-78,-80,-71,-74],
'color': range(4)})
annotations=[
dict(
x=-74,
y=40.8,
xref='latitude',
yref='longitude',
text='Patriots',
showarrow=True,
font=dict(
family='Courier New, monospace',
size=16,
color='#ffffff'
),
align='center',
arrowhead=2,
arrowsize=1,
arrowwidth=2,
arrowcolor='#636363',
ax=0,
ay=-2,
bordercolor='#c7c7c7',
borderwidth=2,
borderpad=4,
bgcolor='#ff7f0e',
opacity=0.8
)
]
marker = dict(
size = 8,
opacity = 0.8,
reversescale = True,
autocolorscale = False,
symbol = 'square',
line = dict(
width=1,
color='rgba(102, 102, 102)'
),
colorscale = 'Jet',
cmin = 0,
color = df['color'],
cmax = 4,
colorbar=dict(
title="NFL Teams"
)
)
geo = dict(
scope='usa',
projection=dict( type='albers usa' ),
showland = True,
landcolor = "rgb(250, 250, 250)",
subunitcolor = "rgb(217, 217, 217)",
countrycolor = "rgb(217, 217, 217)",
countrywidth = 0.5,
subunitwidth = 0.5
)
data = [ dict(
type = 'scattergeo',
locationmode = 'USA-states',
lon = df['longitude'],
lat = df['latitude'],
text = 'text' ,
mode = 'markers',
marker = marker
)]
layout = dict(
title = '',
colorbar = True,
annotations= annotations,
geo = geo
)
fig = dict( data=data, layout=layout )
py.iplot( fig, validate=False, filename='file1' )