Create a list from titanic csv and chart using matplot.pyplot and savefig
<p>I'm playing around with the Kaggle Titanic train.csv to get more comfortable with lists, csv reader, and matplot charts. Nevermind that the list I'm creating isn't really necessary to display the data in a chart (or that the chart is a line...). I just want to make a simple chart and save it, but when I look for it in the current directory it's not there. Is there anything wrong with the code (besides not being very 'pythonic')?</p>

<p>I'm running Windows and executing in Powershell.</p>

<p>Element 1 in the csv determines survivors, element 4 specifies male/female, element 5 is age. I want the chart to display the number of male survivors of each age listed before I move on to something meaningful.</p>

<pre><code>import csv
import matplotlib.pyplot as plt

f = open("PATH/train.csv")
csv_f = csv.reader(f)

class survivordata:
    def male_test(self, data):

        for row in data:
            tlist = list(row)
            # now I have a list of tuples.
            if tlist[4] == "male" and tlist[1] == 1:
                males = []
                males.append(row)
                c = counter(males)
                plt.plot(males[5], c[5], color = 'blue', marker = 'x',
                linestyle = 'solid'
                )
                plt.title("Male Survivors")
                plt.ylabel("Number Survivors")

                plt.savefig("graph.png")
</code></pre>

<p>Appreciate the feedback.</p>

<p><code>csv</code> module doesn't convert text into <code>int</code> so you have to compare <code>tlist[1]</code> with text <code>"1"</code>.</p>

<p>If this doesn't work then add many <code>print(some_usefull_message)</code> in code to see which part is executed. And print variable to see values. Mostly it helps to resolve problem.</p>

python csv matplotlib