0

I created a simple csv file with numbers that approach pi and I would like to create and store the output as a png. I have a very simple csv, each tow contains the number I want to graph and

import pandas as pd
import csv
import matplotlib.pyplot as plt

from decimal import Decimal

def create_png():

df = pd.read_csv('sticks.csv', names=["xstk", "stk"])

sumdf = df.sum(0)
num1 = sumdf['xstk']
num2 = sumdf['stk']
total = num1 + num2

aproxpi = [(2*float(total))/num1]

with open('aproxpi.csv', 'a') as pifile:
    piwriter = csv.writer(pifile, delimiter= ' ')
    piwriter.writerow(aproxpi)

Piplot = pd.read_csv('aproxpi.csv', names=['~Pi'])

#Piplot.groupby('~Pi')


Piplot.plot(title='The Buffon Needle Experiment')   




if __name__ == "__main__":
    create_png()

When I run this code nothing happens. If I use the show method on the AxesSubPlot I raise an exception. How can this be accomplished?

2 Answers 2

2

You need to call plt.show() to actually see the plot.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I attempted to call show() but did not realize it was a method of plt.
0

This code seems very incomplete - is there more you can give us?

It may be that Piplot.plot needs to have x and y specified, instead of simply a title. I believe that you need to create a new plot object and pass the data into it, rather than calling data.plot() as you are now. See the documentation.

Additionally, taking a look at this question may help.

1 Comment

I have now edited it to show the whole code, I will try to do that now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.