Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust axis scaling with pandas parallel_coordinates

I'm working on plotting some data with pandas in the form of parallel coordinates, and I'm not too sure how to go about setting the the y-axis scaling.

Here's my code:

import matplotlib
import matplotlib.pyplot as plt
import pandas as panda
from pandas.tools.plotting import parallel_coordinates

def parallel_coords(filename):

    matplotlib.style.use('ggplot')

    data = panda.read_csv(filename)
    parallel_coordinates(data[['postcode','2005','2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015']], 'postcode')
    plt.show()

parallel_coords('crime_data_updated.csv')

The output looks like this: enter image description here You can see that there's heaps of data. How can I change the y axis scale? For example making it logarithmically scaled or choosing to only display between 0 - 5000. I've had a look at the pandas documentation but it has not helped thus far.

like image 695
JavascriptLoser Avatar asked Jan 31 '26 11:01

JavascriptLoser


1 Answers

It is indeed possible to scale axes and the kind of data you have seems like very suitable to try to scale.

Seems like all you need to do is define that y axis is to be scaled - without needing to do any scaling yourself - and matplolib.pyplot does all graft for you.

Try with this:

parallel_coordinates(data[['postcode','2005','2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015']], 'postcode')
plt.yscale('log') ## <- should be enough to define log scaling on your y-axis here
plt.show()

You can see documentation here

I hope that helps!

like image 153
Thanos Avatar answered Feb 03 '26 00:02

Thanos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!