Fixed out-of-range error while plotting