0

I have the following sample dataset:

InfectionDate   FER0    FER1    FER2    FER3    FER4    FER5    FER6    FER7    FER8    FER9    FER10   FER11   FER12   FER13
0   2   NaN NaN 319.0   NaN NaN NaN NaN NaN NaN NaN 510.2   NaN NaN NaN
1   1   NaN 886.2   NaN NaN NaN 960.8   NaN NaN NaN 915.9   NaN NaN NaN NaN
2   1   NaN NaN NaN NaN NaN NaN NaN NaN 847.2   NaN NaN NaN NaN NaN
3   1   NaN NaN NaN NaN NaN NaN 2308.0  1798.0  1517.0  NaN 1465.0  NaN NaN NaN
4   2   NaN NaN NaN NaN NaN NaN 2650.0  NaN NaN 1318.0  NaN NaN NaN NaN
5   2   NaN NaN NaN NaN NaN NaN 452.0   345.2   NaN NaN NaN NaN NaN NaN
6   2   NaN NaN NaN NaN 506.9   431.1   NaN NaN NaN NaN 852.8   NaN NaN NaN
7   2   NaN 184.0   NaN 535.0   NaN NaN NaN 1867.0  NaN NaN NaN NaN NaN 1097.0
8   0   217.0   NaN NaN NaN NaN NaN NaN NaN NaN 255.0   NaN 269.0   269.0   NaN
9   0   NaN NaN NaN 2263.0  NaN NaN NaN NaN NaN 2532.0  NaN NaN NaN NaN

I am plotting the values using the following code:

plt.figure(figsize=(13, 10))
trend_df = pd.read_clipboard(sep="\s+")
melted_df = trend_df.melt(
    id_vars="InfectionDate",
    value_vars=["FER{}".format(i) for i in range(14)],
    var_name="Marker",
)
ax = sn.lineplot(
    x="Marker",
    y="value",
    data=melted_df,
    hue="InfectionDate",
    estimator=np.mean,
    palette="RdYlGn",
    legend=False,
    sort=False,
)

But seaborn still seems to be applying its own sorting:

enter image description here

How can I fix this?

K G
  • 1,715
  • 6
  • 21
  • 29
  • 3
    Please provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) that includes a toy dataset (refer to [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples)) – Diziet Asahi May 07 '20 at 13:07
  • @DizietAsahi ok done – K G May 07 '20 at 14:18

1 Answers1

1

I don't exactly know what is the result you are looking for, but the problem comes from the fact that lineplot expects the x column to be numeric (the documentation says about x,y: "Input data variables; must be numeric").

I think you are looking for pointplot instead, which plots on a categorical axis.

ax = sn.pointplot(...)

enter image description here

Diziet Asahi
  • 38,379
  • 7
  • 60
  • 75