I have the following code in Python. My problem is I need the y axis to be fixed
ID: 660935 • Letter: I
Question
I have the following code in Python. My problem is I need the y axis to be fixed to the following ranging from 0:00, 01:00, 02:00, 03:00 etc up to 12:00. AS of now it's only plotting the times for the data I have. The x axis is fine the way it is. I need for my program to be able to plot the data i have with the fixed Y axis ranging from 00:00 to 12:00. My csv is in the following format.ML INT 0.1 534.15 0:00 ML EXT 0.25 654.23 3:00 ML INT 0.35 743.12 6:30 ML INT 0.1 534.15 11:00 ML EXT 0.25 654.23 3:30 ML INT 0.35 743.12 7:30
import pandas as pd import matplotlib.pyplot as plt import numpy as np data = pd.read_csv('data.csv', header=None) ints = data[data[1]=='INT'] exts = data[data[1]=='EXT'] INT_index = data[data[1]=='INT'].index EXT_index = data[data[1]=='EXT'].index time = [t for t in data[4]] int_dist = [d for d in ints[3]] ext_dist = [d for d in exts[3]] fig, ax = plt.subplots() ax.scatter(int_dist, INT_index, c='orange', s=150) ax.scatter(ext_dist, EXT_index, c='black', s=150) ax.set_yticks(np.arange(len(data[4]))) ax.set_yticklabels(time) plt.legend(['INT', 'EXT'], loc=4) plt.xlabel('Distance') plt.ylabel('Time') plt.show() ML INT 0.1 534.15 0:00 ML EXT 0.25 654.23 3:00 ML INT 0.35 743.12 6:30
Explanation / Answer
Below your plt.ylabel('Time'), you should mention the limits for y axis :
plt.ylim(0:00, 12:00)