我是一个初学者,尝试使用袖扣制作散点图。包含最佳拟合行的可选参数是bestfit=True
。生成this chart的代码如下所示:
import pandas as pd
from plotly.offline import iplot, init_notebook_mode
import cufflinks
cufflinks.go_offline(connected=True)
init_notebook_mode(connected=True)
df = pd.read_csv('https://raw.githubusercontent.com/inferentialthinking/inferentialthinking.github.io/master/data/nba2013.csv')
df.iplot(
z='Weight'
, x='Age in 2013'
, y='Weight'
, kind='scatter'
, mode='markers'
, xTitle='Age'
, yTitle="Weight"
, title="NBA players' weight and age"
, text='Name'
, theme='solar'
, bestfit=True
#, categories='Position'
)
但是,当我添加参数categories='Position'
(在本例中删除“#”)以创建颜色分类(将球员分成后卫、中锋和前锋)时,最佳匹配线消失See chart of this here.我没有收到任何错误消息,只是没有最佳拟合线了
袖扣有助于最佳贴合参数说明:
bestfit : boolean or list
If True then a best fit line will be generated for
all columns.
If list then a best fit line will be generated for
each key on the list.
我想为三个类别中的每一个获得一条最佳拟合线(即三条最佳拟合线)。我不明白如何使用列表为列表中的每个键生成一个最佳匹配行。如果可能的话,在这种情况下,如果有人能解释一下怎么做就好了
非常感谢您的帮助
我非常喜欢袖扣,但使用plotly express更容易实现您的目标:
这种方法在许多方面类似于袖扣。唯一真正的概念是
px.scatter
使用size
,其中cufflinks
使用z
。当然,px.scatter
使用color
参数为Position
的每个子类别生成趋势线相关问题 更多 >
编程相关推荐