3

I'm plotting speed measurements for a categorical variable with the possible names 'up', 'mid' and 'down'. If I make this plot in pyplot, the order of the names is mid-up-down. How can I force pyplot to show these in the order down-mid-up or up-mid-down?enter image description here

DavidG
  • 24,279
  • 14
  • 89
  • 82
Jorre Goossens
  • 139
  • 1
  • 2
  • 10
  • 1
    Possible duplicate of https://stackoverflow.com/questions/3100985/plot-with-custom-text-for-x-axis-points – PEZO Apr 24 '18 at 21:21
  • 1
    It all depends on the order of input. If you plot `plot(["a","b","c"],[1,2,3])` or `plot(["c","a","b"],[3,1,2])`... you always get what you ask for. – ImportanceOfBeingErnest Apr 25 '18 at 01:33
  • Is this really so? I first plot multiple lines for x = ['up', 'mid'] and later plot extra lines for x = ['up', 'mid', 'down']. Shouldn't this then result in the order up-mid-down? – Jorre Goossens Apr 25 '18 at 07:47
  • Instead of plotting lines for x = ['up', 'mid'], I tried using x = ['up', 'mid', 'down'] with NaN as the y-value for 'down'. In this case I did get the correct order. So like you said, you do get what you ask for, although I would think the order should then be up-mid-down, while I now got down-mid-up? Nevertheless, thanks for the help! Just out of curiosity: do you know why I got the wrong order in my first approach? Did pyplot order 'up' and 'mid' alphabetically first and then just added 'down' at the end later on? This alphabetical ordering would also explain why I now got down-mid-up... – Jorre Goossens Apr 25 '18 at 08:07
  • I'm a bit lost with what you get when. Don't forget that this is all about programming, so if you can show the code that does or does not do what you want it would all be easier. If you haven't done so yet, I'd suggest to update to the newest version of matplotlib. If you want to notify someone use the @username notation. – ImportanceOfBeingErnest Apr 25 '18 at 23:44
  • @ImportanceOfBeingErnest My code is quite complex, as I generalised it to choose the variable for the x-axis, the one for determining the colour and two variables to combine to determine the marker style and I'm not so experienced in finding the most efficient way to do this. I'm facing a lot of strict deadlines right now, so I don't want to spend time onto this as it already works. Maybe I'll come back on it once my deadlines are passed, because I'm really curious what caused this behaviour. – Jorre Goossens Apr 28 '18 at 06:56

0 Answers0