0

I would have a following code that generates this lineplot:

enter image description here But I would like to sort x axis to have 1, 2, 3, 0, 4, 5, 6, 7, 8, 9. Moreover, I need to have 0 in the 4/5 between 3 and 4. I tried this:

df_sort = df.sort_values( "ab_test", key=lambda col: col.map( { "0": 14, # see how I insert 0 between 3 and 4 "1": 0, "2": 5, "3": 10, "4": 15, "5": 20, "6": 25, "7": 30, "8": 35, "9": 40, } ), )

But when I try to plot it using:

sns.lineplot(x="ab_test", y="count", data=abtest_sort, hue="cena_percentil")

it gives me the same result as before. How can I fix it, please?

vojtam
  • 1,157
  • 9
  • 34
  • Out of curiosity: why have an x-axis with an order "1, 2, 3, 0, 4, 5, 6, 7, 8, 9"? What kind of data has that order? – 9769953 Jan 17 '22 at 08:01
  • @9769953 these numbers stand for ID and test with ID 0 was done after test number 3. – vojtam Jan 17 '22 at 08:04
  • Since the numbers are ID, you'll need to handle them as categorical data. I'm not directly sure how that is done best, but that may give you a keyword to search on. [This question](https://stackoverflow.com/questions/47255746/change-order-on-x-axis-for-matplotlib-chart) is somewhat related, and has an answer that involves Seaborn, not just Matplotlib. – 9769953 Jan 17 '22 at 08:07
  • Ah, I see now: your numbers are actually strings. Confusing on the plot itself, but otherwise, that makes sense. – 9769953 Jan 17 '22 at 08:08
  • Could you add a dataframe as code that contains the actual data (or some of it)? That is easier to create an answer. – 9769953 Jan 17 '22 at 08:10

0 Answers0