Search code examples
pythonpandasmatplotlibparallel-coordinates

Rotating parallel coordinate axis-names in Pandas


When using some of the built in visualization tools in Pandas, one that is very helpful for me is the parallel_coordinates visualization. However, since I have around 18 features in the dataframe, the bottom of the parallel_coords plot gets really messy.

Therefore, I was wondering if anyone knew how to rotate the axis-names to be vertical rather than horizontal as shown here:

parallel_coordinates example

I did find a way to use parallel_coords in a polar set up, creating a radar-chart; while that was helpful for getting the different features to be visible, that solution doesn't quite work since whenever the values are close to 0, it becomes almost impossible to see the curve. Furthermore, doing it with the polar coord frame required me to break from using pandas' dataframe which is part of what made the this method so appealing.

polar


Solution

  • Use plt.xticks(rotation=90) should be enough. Here is an example with the “Iris” dataset:

    import matplotlib.pyplot as plt
    import pandas as pd
    from pandas.plotting import parallel_coordinates
    
    data = pd.read_csv('iris.csv')
    parallel_coordinates(data, 'Name')
    plt.xticks(rotation=90)
    plt.show()
    

    enter image description here