最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

altair - Faceting and fill color glitch? - Stack Overflow

programmeradmin11浏览0评论

Newbie question coming! My aim is to have filled dots in a chart together with a linear line. I am experiencing fill changes whilst using faceting in Altair; I think that I am just not using the most straightforward syntax.

My code for the chart is:

chart = alt.Chart(exercise_df).mark_point(fillOpacity=1).encode(
    x = alt.X('IntensityOfRemindersDelta'),
    y = alt.Y('HealthyEatingScoreDelta'),
    color = alt.Color('Individual'),
    fill = alt.Fill('Individual')
).properties(
    height=500,
    width=500,
)

line = (chart
    .mark_line()
    .encode(
        color=alt.value("#dddddd")
    )
    .transform_regression('IntensityOfRemindersDelta', 'HealthyEatingScoreDelta')
)

(chart + line).facet('Individual')

The plot looks like:

Data to replicate the issue is:

IndNo,Individual,IntensityOfReminders,HealthyEatingScore,IntensityOfReminder,IntensityOfRemindersMean,HealthyEatingScoreMean,IntensityOfRemindersDelta,HealthyEatingScoreDelta
1,You,1.98,0.14,0.23,3.87,0.81,-1.89,-0.67
1,You,4.58,1.37,0.54,3.87,0.81,0.71,0.56
1,You,2.81,0.77,0.33,3.87,0.81,-1.06,-0.05
1,You,2.96,0.85,0.35,3.87,0.81,-0.92,0.03
1,You,5.07,0.50,0.59,3.87,0.81,1.20,-0.31
1,You,3.14,1.27,0.37,3.87,0.81,-0.73,0.45
1,You,5.80,0.93,0.68,3.87,0.81,1.93,0.12
1,You,4.63,0.69,0.54,3.87,0.81,0.76,-0.12
2,Me,6.10,1.03,0.71,4.01,0.44,2.09,0.60
2,Me,5.06,0.21,0.59,4.01,0.44,1.05,-0.23
2,Me,2.60,0.00,0.30,4.01,0.44,-1.41,-0.44
2,Me,2.71,0.11,0.32,4.01,0.44,-1.30,-0.33
2,Me,2.13,0.57,0.25,4.01,0.44,-1.88,0.13
2,Me,2.37,0.21,0.28,4.01,0.44,-1.65,-0.23
2,Me,6.91,1.24,0.81,4.01,0.44,2.90,0.80
2,Me,4.21,0.13,0.49,4.01,0.44,0.20,-0.30
3,Shamma,5.95,0.75,0.69,6.38,0.61,-0.44,0.14
3,Shamma,4.68,0.98,0.55,6.38,0.61,-1.71,0.38
3,Shamma,7.40,0.72,0.86,6.38,0.61,1.02,0.11
3,Shamma,4.06,0.48,0.48,6.38,0.61,-2.32,-0.13
3,Shamma,7.85,0.30,0.92,6.38,0.61,1.47,-0.31
3,Shamma,7.55,0.85,0.88,6.38,0.61,1.17,0.25
3,Shamma,6.99,0.17,0.82,6.38,0.61,0.61,-0.44
3,Shamma,6.59,0.59,0.77,6.38,0.61,0.21,-0.01
4,Liqing,8.56,0.67,1.00,6.79,0.41,1.77,0.26
4,Liqing,6.89,0.61,0.81,6.79,0.41,0.10,0.19
4,Liqing,6.12,0.81,0.72,6.79,0.41,-0.67,0.39
4,Liqing,7.95,0.38,0.93,6.79,0.41,1.17,-0.04
4,Liqing,6.88,0.04,0.80,6.79,0.41,0.10,-0.37
4,Liqing,4.73,0.43,0.55,6.79,0.41,-2.05,0.02
4,Liqing,8.30,0.36,0.97,6.79,0.41,1.52,-0.05
4,Liqing,4.85,0.00,0.57,6.79,0.41,-1.93,-0.41

Newbie question coming! My aim is to have filled dots in a chart together with a linear line. I am experiencing fill changes whilst using faceting in Altair; I think that I am just not using the most straightforward syntax.

My code for the chart is:

chart = alt.Chart(exercise_df).mark_point(fillOpacity=1).encode(
    x = alt.X('IntensityOfRemindersDelta'),
    y = alt.Y('HealthyEatingScoreDelta'),
    color = alt.Color('Individual'),
    fill = alt.Fill('Individual')
).properties(
    height=500,
    width=500,
)

line = (chart
    .mark_line()
    .encode(
        color=alt.value("#dddddd")
    )
    .transform_regression('IntensityOfRemindersDelta', 'HealthyEatingScoreDelta')
)

(chart + line).facet('Individual')

The plot looks like:

Data to replicate the issue is:

IndNo,Individual,IntensityOfReminders,HealthyEatingScore,IntensityOfReminder,IntensityOfRemindersMean,HealthyEatingScoreMean,IntensityOfRemindersDelta,HealthyEatingScoreDelta
1,You,1.98,0.14,0.23,3.87,0.81,-1.89,-0.67
1,You,4.58,1.37,0.54,3.87,0.81,0.71,0.56
1,You,2.81,0.77,0.33,3.87,0.81,-1.06,-0.05
1,You,2.96,0.85,0.35,3.87,0.81,-0.92,0.03
1,You,5.07,0.50,0.59,3.87,0.81,1.20,-0.31
1,You,3.14,1.27,0.37,3.87,0.81,-0.73,0.45
1,You,5.80,0.93,0.68,3.87,0.81,1.93,0.12
1,You,4.63,0.69,0.54,3.87,0.81,0.76,-0.12
2,Me,6.10,1.03,0.71,4.01,0.44,2.09,0.60
2,Me,5.06,0.21,0.59,4.01,0.44,1.05,-0.23
2,Me,2.60,0.00,0.30,4.01,0.44,-1.41,-0.44
2,Me,2.71,0.11,0.32,4.01,0.44,-1.30,-0.33
2,Me,2.13,0.57,0.25,4.01,0.44,-1.88,0.13
2,Me,2.37,0.21,0.28,4.01,0.44,-1.65,-0.23
2,Me,6.91,1.24,0.81,4.01,0.44,2.90,0.80
2,Me,4.21,0.13,0.49,4.01,0.44,0.20,-0.30
3,Shamma,5.95,0.75,0.69,6.38,0.61,-0.44,0.14
3,Shamma,4.68,0.98,0.55,6.38,0.61,-1.71,0.38
3,Shamma,7.40,0.72,0.86,6.38,0.61,1.02,0.11
3,Shamma,4.06,0.48,0.48,6.38,0.61,-2.32,-0.13
3,Shamma,7.85,0.30,0.92,6.38,0.61,1.47,-0.31
3,Shamma,7.55,0.85,0.88,6.38,0.61,1.17,0.25
3,Shamma,6.99,0.17,0.82,6.38,0.61,0.61,-0.44
3,Shamma,6.59,0.59,0.77,6.38,0.61,0.21,-0.01
4,Liqing,8.56,0.67,1.00,6.79,0.41,1.77,0.26
4,Liqing,6.89,0.61,0.81,6.79,0.41,0.10,0.19
4,Liqing,6.12,0.81,0.72,6.79,0.41,-0.67,0.39
4,Liqing,7.95,0.38,0.93,6.79,0.41,1.17,-0.04
4,Liqing,6.88,0.04,0.80,6.79,0.41,0.10,-0.37
4,Liqing,4.73,0.43,0.55,6.79,0.41,-2.05,0.02
4,Liqing,8.30,0.36,0.97,6.79,0.41,1.52,-0.05
4,Liqing,4.85,0.00,0.57,6.79,0.41,-1.93,-0.41
Share Improve this question edited Feb 7 at 13:57 spdrnl asked Feb 5 at 10:06 spdrnlspdrnl 1136 bronze badges 2
  • Hi @spdrnl, could you update your question with a code sample that includes data? – kgoodrick Commented Feb 6 at 20:13
  • Hi @kgoodrick. Absolutely. Thank you for taking interest. – spdrnl Commented Feb 7 at 13:58
Add a comment  | 

1 Answer 1

Reset to default 0

Answering my own question. This code snippet gives the correct result with the right fill color.

chart = (alt.Chart(exercise_df).mark_point(fillOpacity=1).encode(
    x = alt.X('IntensityOfRemindersDelta'),
    y = alt.Y('HealthyEatingScoreDelta'),
    color = alt.Color('Individual'),
    fill = alt.Fill('Individual')
    ).properties(
        height=500,
        width=500,
    )
)

line = (alt.Chart(exercise_df)
    .mark_line(color="#AAAAAA")
    .encode(
        x = alt.X('IntensityOfRemindersDelta'),
        y = alt.Y('HealthyEatingScoreDelta'),
    )
    .transform_regression('IntensityOfRemindersDelta', 'HealthyEatingScoreDelta')
)

(chart + line).facet('Individual')
发布评论

评论列表(0)

  1. 暂无评论