How do I plot a 2D array graph in Python using matplotlib
Question: I'm having a little bit of trouble in creating a graph using 2D array data in
python.

I have a txt file which holds data like this:

    
    
    0 2 4 6 8
    -1 -2 -1 2 4
    0 1 0 -1 0
    1 3 5 7 6
    0 1 -1 -3 2
    1 -1 1 1 0
    

(this is shortened, my actual file is 100*10000

So essentially a 5x6 array.

I would like the x axis to be the total number of elements in each array which
is always going to be a fixed limit of 5. The Y axis needs to be the actual
data point from the txt file. Which leaves 6 lines in total being created.

Below is a quickly drawn photo in paint: [Image here (low score, cannot
embed)](http://i.stack.imgur.com/mOW7J.png) So Y = data value, X = length of
each individual array and the lines are how many total arrays their are.

I would like to use this style, however if possible make the line width 1px as
there are going to be roughly 10,000 lines drawn.
<http://matplotlib.org/examples/style_sheets/plot_fivethirtyeight.html>

I have had a try with some of the code, and this is where I got stuck, I could
read in the data and store it in some kind of array, but then was unable to
use that for making the graph. (Top part is my code for reading it in, bottom
part is the example code from the fivethirtyeight style.

    
    
    import numpy as np
    import matplotlib.pyplot as plt
    
    with open('thisone.txt') as file:
        array2d = [[int(digit) for digit in line.split()] for line in file]
    
    
    from matplotlib import pyplot as plt
    import numpy as np
    
    x = np.linspace(0, 10)
    
    with plt.style.context('fivethirtyeight'):
        plt.plot(x, np.sin(x) + x + np.random.randn(50))
        plt.plot(x, np.sin(x) + 0.5 * x + np.random.randn(50))
        plt.plot(x, np.sin(x) + 2 * x + np.random.randn(50))
    
    
    plt.show() 
    


Answer: After you read in the data, iterate over the rows in the data and plot a graph
row vs. range(len(row)).

    
    
    import numpy as np
    import matplotlib.pyplot as plt
    
    with open('thisone.txt') as file:
        array2d = [[int(digit) for digit in line.split()] for line in file]
    
    with plt.style.context('fivethirtyeight'):
        for row in array2d:
            plt.plot(xrange(len(row)), row)
    
    plt.show()
    

