【问题标题】:Parallel coordinates plot with skipped coordinates带有跳过坐标的平行坐标图
【发布时间】:2017-07-22 05:42:45
【问题描述】:

人们在 100 米、400 米、1600 米的赛道上比赛,并记录他们的完成时间。我想在平行坐标图中显示每个赛车手的数据。一些赛车手可能无法完成赛道。在这种情况下,我想以某种方式对其进行标记,无论是无限点还是特定轨道的颜色。

作为一个例子,我在paint中绘制了一个平行坐标图:
Lazyman 1600m 的赛道还没有走完,这里标有 x。

以下“racing.csv”中给出了一个示例数据集:

RACER,TRACK.100m,TRACK.400m,TRACK.1500m
Superman,0.1,0.5,1
Lazyman,200,900,Inf

我已经尝试过使用 pandas 的解决方案:

import pandas
from pandas.tools.plotting import parallel_coordinates
import matplotlib.pyplot as plt

d = pandas.read_csv('racing.csv')

f = plt.figure()
parallel_coordinates(d, 'RACER')
f.axes[0].set_yscale('log')

plt.show()

这给出了 Lazyman 在 1600m 处没有 Inf 值的图:

我还为ggplot准备了一个csv(可能有更好的方法):

RACER,TRACK,TIME
Superman,100m,0.1
Superman,400m,0.5
Superman,1600m,1
Lazyman,100m,200
Lazyman,400m,900
Lazyman,1600m,Inf

使用 ggplot:

require(ggplot2)
d <- read.csv('racing2.csv')
g <- ggplot(d) + geom_line(aes(x=TRACK,y=TIME,group=RACER, color=RACER))
g <- g + scale_y_log10()
ggsave('ggplot.png')

我走近了:


因为这显示了一个无穷大值,但没有对其进行任何注释。

任何解决方案,无论是 Python 还是 R,都将受到赞赏。此外,我们感谢有关标记未完成比赛的建议。

【问题讨论】:

  • 到目前为止你有什么尝试,懒人不想从0开始...
  • 很抱歉,您能否澄清一下。 Lazyman 还没有完成 1600 m,这就是为什么他在无限时被标记为 x。到目前为止,我正在谷歌搜索,如果我找到答案,我会发布它。
  • 您必须先从一些数据和一个体面的第一次尝试开始,并解决一个特定的问题。
  • 不画400米到1600米之间的线怎么样?
  • @Axeman:这样可以吗?

标签: python r plot


【解决方案1】:

使用 R 和 ggplot2:

构建一些虚假数据:

df <- data.frame(ID = factor(c(rep(1, 3), rep(2, 3), rep(3, 3)), labels = c('Realman', 'Lazyman', 'Superman')),
             race = factor(rep(seq(1,3,1), 3), labels = c('100m', '400m', '1600m')),
             runTime = c(8.9, 20.5, 150.9, 100.1, 300.3, +Inf, 1.2, 5, +Inf))

        ID  race runTime
# 1  Realman  100m     8.9
# 2  Realman  400m    20.5
# 3  Realman 1600m   150.9
# 4  Lazyman  100m   100.1
# 5  Lazyman  400m   300.3
# 6  Lazyman 1600m     Inf
# 7 Superman  100m     1.2
# 8 Superman  400m     5.0
# 9 Superman 1600m     Inf

结果:

代码:

ggplot(filter(df, runTime != +Inf), aes(x = race, y = runTime, group = ID, color = ID)) + 
    geom_line(size = 2) +
    geom_point(size = 4) +

    geom_line(data = df, linetype = 'dashed', size = 1) +        
    geom_point(data = df, shape = 21, size = 1) +

    geom_text(aes(label = runTime), position = position_nudge(y = -.1)) +

    scale_y_continuous(trans = 'log10', breaks = c(1, 10, 100, 1000)) +
    scale_x_discrete('Track') +
    scale_color_manual('Racer', values = brewer.pal(length(levels(df$ID)), 'Set1')) +

    theme(panel.background = element_blank(),
          panel.grid.major.x = element_line(colour = 'lightgrey', size = 25),
          legend.position = 'top',
          axis.line.y = element_line('black', .5, arrow = arrow()))

【讨论】:

  • 我已接受答案并创建了一个后续问题stackoverflow.com/questions/42560935/…。如果您能看一下,我将不胜感激。
  • 我在发帖后也发现了你在后续中指出的问题。将看看asaic。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-04
  • 2014-09-02
  • 2020-02-27
  • 2013-06-18
  • 1970-01-01
相关资源
最近更新 更多