How can I plot an axis on MatPlotLib in terms of text, not numbers, taken from a CSV file?
Question: I have a .csv file that looks something like this (small sample, disregard the
periods):

    
    
    Year | Month | Carrier | Elapsed Time
    
    1987 | 10.......|UN.......|15
    
    1987 | 11.......|AM.......|17
    
    1987 | 12.......|HK.......|20
    

I'm plotting a 3D graph in MatPlotLib (Python), where the z-axis (vertical
axis) is Elapsed time, the x-axis is the month, and the y-axis is the carrier.
If I'm not mistaken MatPlotLib only allows the values of each axis to be an
integer and not a string. That's where the problem lies: the carrier values
are strings, or letters, such as UN, AM, and HK. My code so far is:

    
    
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    
    readFile = open('/home/andrew/Downloads/1987.txt', 'r')
    sepFile = readFile.readlines()[1:50000]
    readFile.close()
    
    rect = fig.patch
    rect.set_facecolor('white')
    
    X = []
    Y = []
    Z = []
    
    for plotPair in sepFile:
        xAndY = plotPair.split(',')
        X.append(int(xAndY[1]))
        Y.append(str(xAndY[2])) #Putting str() instead of int() didn't solve the problem
        Z.append(int(xAndY[3]))
    
    ax.scatter(X,Y,Z, c ='r', marker='o')
    
    ax.set_xlabel('x axis')
    ax.set_ylabel('y axis')
    ax.set_zlabel('z axis')
    
    plt.show()
    

I understand that I could just say x = [UN, AM, HK] but the problem with this
is that the x list would not be taken from the .csv file. The Python program
wouldn't know which point belongs to which carrier name. I want to be able to
tell Python to search the column with the name of the carrier for each point
and then be able to extract that information so it can plot successfully from
the csv file as shown in the picture:

[3D Graph Skeleton](http://postimg.org/image/6u9cnpf9h/)

I'm still a newbie and getting the hang of Python so I thank you so much for
taking the time to answer. Your help is seriously appreciated.


Answer: Credit goes to the answer by Tom, this is just an adaptation.

Also, I'm pretty sure there are better answers out there but this should work
for what you're doing.

    
    
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    import numpy as np
    
    X = {}
    Z = {}
    
    for plotPair in sepFile:
        xAndY = plotPair.split(',')
        label = str(xAndY[2])
    
        if label in x.keys():
            X[label].append(int(xAndY[1]))
            Z[label].append(int(xAndY[3]))
        else:
            X[label] = [int(xAndY[1])]
            Z[label] = [int(xAndY[3])] 
    
    Y=0
    for label in X.keys():
        ax.scatter(X[label],Y[-1]*np.ones_like(X[label]),Z[label], c ='r', marker='o')
        Y.append(Y[-1]+1)
    
    ax.set_xlabel('x axis')
    ax.set_ylabel('y axis')
    ax.set_zlabel('z axis')
    
    ax.set_yticks(Y)
    ax.set_yticklabels(X.keys())
    

One bonus is that each carrier can have a different colour.

