0

I have a dataframe of volume by country for two specific years. I would like to visualize how those countries change their rank from one year to another. I would like to know if it's possible with matplotlib or seaborn to connect those barplots by phisycally drawing a line outlining the change of rank.

Something like this:

enter image description here

Base data and code:

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

d = {'volume' : [1000, 500, 200, 100, 350, 600], 'year' : [2017, 2017, 2017, 2018, 2018, 2018], 'country' : ['US', 'UK', 'France', 'US', 'UK', 'France']}
df = pd.DataFrame(data=d)

fix, axs = plt.subplots(ncols=2)
sns.barplot(x='volume',y='country', data=df[df['year']==2017].sort_values(by='volume', ascending = False), ax=axs[0])
sns.barplot(x='volume',y='country', data=df[df['year']==2018].sort_values(by='volume', ascending = False), ax=axs[1])
plt.show()
Victor
  • 1,163
  • 4
  • 25
  • 45
  • Maybe you are looking for [Drawing lines between two plots in Matplotlib](https://stackoverflow.com/questions/17543359/drawing-lines-between-two-plots-in-matplotlib)? – ImportanceOfBeingErnest Nov 20 '18 at 19:31
  • 2
    Based on what I understand, maybe the parallel plot is something better suited to your need? https://python-graph-gallery.com/parallel-plot/ – Xiaoyu Lu Nov 20 '18 at 19:44

0 Answers0