Hello. Ive got two functions here. Somehow the program does not go in
to the second function wehn i call it. The bestfit function. Could
some1 help me identify the problem. Heres the code:
import Gnuplot
def bestfit(uinput) :
if not isinstance(uinp ut, list):
return False
else:
sigmax = sigmay = sigmaxy = sigmaxwhl = sigmaxsq = 0
for i in range(len(uinpu t)):
n = len(uinput)
sigmax = uinput[i][0] + sigmax
sigmay = uinput[i][1] + sigmay
sigmaxy = uinput[i][0] * uinput [i][1] + sigmaxy
sigmaxwhl = sigmax * sigmax
sigmaxsq = uinput[i][0] * uinput[i][0] + sigmaxsq
sigmaxsigmay = sigmax * sigmay
num = sigmaxsigmay - (n * sigmaxy)
den = sigmaxwhl - (n* sigmaxsq)
num2 = (sigmax * sigmaxy) - (sigmay * sigmaxsq)
gradient = num / den
intercept = num2 / den
m = gradient
c = intercept
p = Gnuplot.Gnuplot ()
p.plot ('%f * x+%f'%(m,c))
return p
def plot(original, expected, actual):
if not isinstance(orig inal, list):
return False
else:
gp = Gnuplot.Gnuplot ()
gp('set data style lines')
# Make the plot items
plot1 = Gnuplot.PlotIte ms.Data(origina l, title="Original ")
plot2 = Gnuplot.PlotIte ms.Data(expecte d, title="Expected ")
plot3 = Gnuplot.PlotIte ms.Data(actual, title="Acutal")
gp.plot(plot1, plot2, plot3)
bestfit(expecte d)
bestfit(actual)
return gp
-------
import Combine #The name of my file...
gp = Combine.plot( [(2,3), (4,8), (5,9), (6,2)], [(1,7), (3,3), (4,5),
(5,6)], [(1,3), (3,10), (4,8), (7,9) ] )
raw_input() 7 3555 ar**********@gm ail.com wrote:
Hello. Ive got two functions here. Somehow the program does not go in
to the second function wehn i call it. The bestfit function. Could
some1 help me identify the problem. Heres the code:
Same problem as before, you have to keep the Gnuplot instance alive if you
want to see the graph.
Note that instead of
for i in range(len(uinpu t)):
sigmaxy = uinput[i][0] * uinput[i][1] + sigmaxy
you could write
for x, y in uinput:
sigmaxy += x * y
High time to take a look into a good Python tutorial...
# --- combine.py ---
import Gnuplot
def bestfit(uinput) :
sigmax = sigmay = sigmaxy = sigmaxwhl = sigmaxsq = 0
for i in range(len(uinpu t)):
n = len(uinput)
sigmax = uinput[i][0] + sigmax
sigmay = uinput[i][1] + sigmay
sigmaxy = uinput[i][0] * uinput [i][1] + sigmaxy
sigmaxwhl = sigmax * sigmax
sigmaxsq = uinput[i][0] * uinput[i][0] + sigmaxsq
sigmaxsigmay = sigmax * sigmay
num = sigmaxsigmay - (n * sigmaxy)
den = sigmaxwhl - (n* sigmaxsq)
num2 = (sigmax * sigmaxy) - (sigmay * sigmaxsq)
gradient = num / den
intercept = num2 / den
m = gradient
c = intercept
p = Gnuplot.Gnuplot ()
p.plot ('%f * x+%f'%(m,c))
return p
def plot(original, expected, actual):
gp = Gnuplot.Gnuplot ()
gp('set data style lines')
# Make the plot items
plot1 = Gnuplot.PlotIte ms.Data(origina l, title="Original ")
plot2 = Gnuplot.PlotIte ms.Data(expecte d, title="Expected ")
plot3 = Gnuplot.PlotIte ms.Data(actual, title="Acutal")
gp.plot(plot1, plot2, plot3)
return gp
def show_plots(orig inal, expected, actual):
gp = combine.plot( original, expected, actual)
raw_input("firs t")
gp = combine.bestfit (expected)
raw_input("seco nd")
gp = combine.bestfit (actual)
raw_input("thir d")
# --- combine_main.py ---
import combine
combine.show_pl ots([(2,3), (4,8), (5,9), (6,2)], [(1,7), (3,3), (4,5),
(5,6)], [(1,3), (3,10), (4,8), (7,9) ] )
Umm.... Tried this out too.... Laiken heres the error that this
gives..
Traceback (most recent call last):
File "D:\Questions\G radient and C\Gnuplot\Combi ning Best fit and
Plotting\combas d.py", line 3, in <module>
combine.show_pl ots([(2,3), (4,8), (5,9), (6,2)], [(1,7), (3,3),
(4,5), (5,6)], [(1,3), (3,10), (4,8), (7,9) ] )
File "D:\Questions\G radient and C\Gnuplot\Combi ning Best fit and
Plotting\combin e.py", line 54, in show_plots
gp = combine.plot( original, expected, actual)
NameError: global name 'combine' is not defined
Still confused though i get the instance part ur trying to tell me. ar**********@gm ail.com wrote:
Umm.... Tried this out too.... Laiken heres the error that this
gives..
Traceback (most recent call last):
File "D:\Questions\G radient and C\Gnuplot\Combi ning Best fit and
Plotting\combas d.py", line 3, in <module>
combine.show_pl ots([(2,3), (4,8), (5,9), (6,2)], [(1,7), (3,3),
(4,5), (5,6)], [(1,3), (3,10), (4,8), (7,9) ] )
File "D:\Questions\G radient and C\Gnuplot\Combi ning Best fit and
Plotting\combin e.py", line 54, in show_plots
gp = combine.plot( original, expected, actual)
NameError: global name 'combine' is not defined
Still confused though i get the instance part ur trying to tell me.
Sorry, it should have been
def show_plots(orig inal, expected, actual):
gp = plot( original, expected, actual)
raw_input("firs t")
gp = bestfit(expecte d)
raw_input("seco nd")
gp = bestfit(actual)
raw_input("thir d")
Peter
On Jun 13, 12:13*pm, Peter Otten <__pete...@web. dewrote:
arslanbur...@gm ail.com wrote:
Umm.... Tried this out too.... Laiken heres the error that this
gives..
Traceback (most recent call last):
* File "D:\Questions\G radient and C\Gnuplot\Combi ning Best fit and
Plotting\combas d.py", line 3, in <module>
* * combine.show_pl ots([(2,3), (4,8), (5,9), (6,2)], [(1,7), (3,3),
(4,5), (5,6)], [(1,3), (3,10), (4,8), (7,9) ] )
* File "D:\Questions\G radient and C\Gnuplot\Combi ning Best fit and
Plotting\combin e.py", line 54, in show_plots
* * gp = combine.plot( original, expected, actual)
NameError: global name 'combine' is not defined
Still confused though i get the instance part ur trying to tell me.
Sorry, it should have been
def show_plots(orig inal, expected, actual):
* * gp = plot( original, expected, actual)
* * raw_input("firs t")
* * gp = bestfit(expecte d)
* * raw_input("seco nd")
* * gp = bestfit(actual)
* * raw_input("thir d")
Peter
Tried that out too. No error however, best fit lines still not being
made on the graph. Only the 3 plot lines show up. ar**********@gm ail.com wrote:
Tried that out too. No error however, best fit lines still not being
made on the graph. Only the 3 plot lines show up.
Sorry, I don't know gnuplot, so I can't help you with any but the obvious
(read: Python) errors.
Peter ar**********@gm ail.com wrote:
Still confused though i get the instance part ur trying to tell me.
Tried that out too. No error however, best fit lines still not being
made on the graph. Only the 3 plot lines show up.
Gave it another shot. You might want something like
from __future__ import division
import Gnuplot
def bestfit(uinput, **kw):
sigmax = sigmay = sigmaxy = sigmaxsq = 0
for x, y in uinput:
sigmax += x
sigmay += y
sigmaxy += x * y
sigmaxsq += x * x
n = len(uinput)
sigmaxwhl = sigmax * sigmax
sigmaxsigmay = sigmax * sigmay
num = sigmaxsigmay - n * sigmaxy
den = sigmaxwhl - n * sigmaxsq
num2 = sigmax * sigmaxy - sigmay * sigmaxsq
gradient = num / den
intercept = num2 / den
return Gnuplot.Func('% f * x+%f' % (gradient, intercept), **kw)
def plot(original, expected, actual):
gp = Gnuplot.Gnuplot ()
gp('set data style lines')
# Make the plot items
plot1 = Gnuplot.PlotIte ms.Data(origina l, title="Original ")
plot2 = Gnuplot.PlotIte ms.Data(expecte d, title="Expected ")
plot3 = Gnuplot.PlotIte ms.Data(actual, title="Actual")
bf2 = bestfit(expecte d, title="Best fit expected")
bf3 = bestfit(actual, title="Best fit actual")
gp.plot(plot1, plot2, plot3, bf2, bf3)
return gp
if __name__ == "__main__":
gp = plot( [(2,3), (4,8), (5,9), (6,2)], [(1,7), (3,3), (4,5), (5,6)],
[(1,3), (3,10), (4,8), (7,9) ] )
raw_input()
It's all in one file for simplicity. Note that I did not check the best fit
algorithm, just tried to simplify what you already had. Use at your own
risk.
Peter
Got the problem solved finally. Missed out theses two lines:
plot1 = Gnuplot.PlotIte ms.Data(origina l, title="Original ")
plot2 = Gnuplot.PlotIte ms.Data(expecte d, title="Expected ")
plot3 = Gnuplot.PlotIte ms.Data(actual, title="Acutal")
plot4 = Gnuplot.PlotIte ms.Func('%f * x+%f'%(bf1[0],bf1[1]), title
= "Expected Best Fit")
plot5 = Gnuplot.PlotIte ms.Func('%f * x+%f'%(bf2[0],bf2[1]), title
= "Actual Best Fit")
The last 2 ones.... thnx nyways This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dr. Colombes |
last post by:
What is the easiest way to generate some plots and graphs in Python ?
Specifically interested in simple histograms and scatter plots with
circles and regression lines.
Thanks for your suggestions.
|
by: Russ |
last post by:
I'm interested in setting up a web page where live data can be
displayed in real-time on the web page.
For example: I would like to display a (nice looking) graph of some
data value versus time and have the graph update every second without
the user having to do anything like hit a refresh button. The data to
plot is readily available from an application running on the server - I
can expose it in whatever way is needed (currently easily...
|
by: Chapman |
last post by:
Is it possible to plot the graph as an output of my program in C? It can be
a simple graph as quadratic curves for example
or a correlation between 2 variables only.
Thanks
|
by: wayne |
last post by:
i want to plot a line graph. The values that I obtain are the RGB value
of a TIFF image. i m plotting RGB values vs value(1,2,3..) so when
generated the RGB values, there will b a column of values for me t
plot the line graph
thanks alot
Peteroid wrote:
> What kind of 'plot' of the data do you want to do? A histogram ca
> be done
|
by: diffuser78 |
last post by:
My python program spits lot of data. I take that data and plot graphs
using OfficeOrg spredsheet. I want to automate this task as this takes
so much of time. I have some questions.
1. Which is the best graph plotting utility in python or linux. Can I
write a code in such a way that my python code automatically gives me a
graph. I know little about gnuplot. If you know any better tool without
much learning curve please tell me in Linux.
...
| |
by: robert |
last post by:
What is a good library for plotting graphs to (compressed) gif / jpg
images?
Has anybody experience with this?
I want to put some simple 2D (and maybe 3D) graph data visualization on
a web server. Currently I test-output the data through Gnuplot.py &
Gnuplot.
I'm quite confused about
http://wiki.python.org/moin/NumericAndScientific/Plotting which would
|
by: arslanburney |
last post by:
Hello. Was trying to create a simple plotting function. Wasnt working
however. If i write the same code without putting it inside a function
it works. :S. Could some1 tell me the problem? Heres the code:
# File name Plotting2
import Gnuplot
def plot(original, expected, actual):
|
by: arslanburney |
last post by:
Hello. Needed some help again. Im trying to calculate the best fit
line here. Given a set of points in a list. However, wirte in the end
where i plot the line it tells me tht the variable is not defined.
Either try correcting this or tell me a subsitute that i could use.
Thnks. Heres the code:
#File name Bestfit.py
import Gnuplot
|
by: Helmut Michels |
last post by:
Dear C/C++ programmers,
I am pleased to announce version 9.4 of the data plotting software
DISLIN.
DISLIN is a high-level and easy to use plotting library for
displaying data as curves, bar graphs, pie charts, 3D-colour plots,
surfaces, contours and maps. Several output formats are supported
such as X11, VGA, PostScript, PDF, CGM, WMF, HPGL, TIFF, GIF, PNG,
BMP and SVG.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |