Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69422 > unrolled thread

Line of best fit

Started byJamie Mitchell <jamiemitchell1604@gmail.com>
First post2014-03-31 04:29 -0700
Last post2014-04-01 01:00 +0000
Articles 5 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  Line of best fit Jamie Mitchell <jamiemitchell1604@gmail.com> - 2014-03-31 04:29 -0700
    Re: Line of best fit Roy Smith <roy@panix.com> - 2014-03-31 08:21 -0400
      Re: Line of best fit Sturla Molden <sturla.molden@gmail.com> - 2014-04-01 00:44 +0000
    Re: Line of best fit Moritz Beber <moritz.beber@gmail.com> - 2014-03-31 13:50 +0200
    Re: Line of best fit Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-04-01 01:00 +0000

#69422 — Line of best fit

FromJamie Mitchell <jamiemitchell1604@gmail.com>
Date2014-03-31 04:29 -0700
SubjectLine of best fit
Message-ID<0fb15100-15e8-46d6-a38f-b187c7012e62@googlegroups.com>
I am new to python so apologies for the ignorance with this question.

How would I apply a line of best fit to a plot?

My data are netCDF4 data files and this is essentially what I have done so far:

swh1=netCDF4.Dataset('filename','r')
hs1=swh1.variables['hs']

swh2=netCDF4.Dataset('filename'.'r')
hs2=swh2.variables['hs']

plt.plot(hs1,hs2,'.')

Cheers,

Jamie

[toc] | [next] | [standalone]


#69425

FromRoy Smith <roy@panix.com>
Date2014-03-31 08:21 -0400
Message-ID<roy-157E04.08214831032014@news.panix.com>
In reply to#69422
In article <0fb15100-15e8-46d6-a38f-b187c7012e62@googlegroups.com>,
 Jamie Mitchell <jamiemitchell1604@gmail.com> wrote:

> I am new to python so apologies for the ignorance with this question.
> 
> How would I apply a line of best fit to a plot?

Python has nothing built-in which does that, but there are plenty of 
add-on modules which do those sorts of things.  One popular one is 
statsmodels (http://statsmodels.sourceforge.net/)

> plt.plot(hs1,hs2,'.')

Please tell us more about the environment you're working in.  I'm 
guessing from the fact that you're calling plt.plot(), that you've 
already got some add-on modules loaded.  Pandas, maybe?

[toc] | [prev] | [next] | [standalone]


#69457

FromSturla Molden <sturla.molden@gmail.com>
Date2014-04-01 00:44 +0000
Message-ID<mailman.8761.1396313094.18130.python-list@python.org>
In reply to#69425
Roy Smith <roy@panix.com> wrote:

> Please tell us more about the environment you're working in.  I'm 
> guessing from the fact that you're calling plt.plot(), that you've 
> already got some add-on modules loaded.  Pandas, maybe?

Probably matplotlib.pyplot

[toc] | [prev] | [next] | [standalone]


#69430

FromMoritz Beber <moritz.beber@gmail.com>
Date2014-03-31 13:50 +0200
Message-ID<mailman.8742.1396272420.18130.python-list@python.org>
In reply to#69422

[Multipart message — attachments visible in raw view] — view raw

None of these are in the standard library but why re-invent the wheel?

Using numpy:
http://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html

scipy:
http://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.stats.linregress.html

statsmodels:
http://statsmodels.sourceforge.net/devel/examples/notebooks/generated/ols.html


On Mon, Mar 31, 2014 at 1:29 PM, Jamie Mitchell <jamiemitchell1604@gmail.com
> wrote:

> I am new to python so apologies for the ignorance with this question.
>
> How would I apply a line of best fit to a plot?
>
> My data are netCDF4 data files and this is essentially what I have done so
> far:
>
> swh1=netCDF4.Dataset('filename','r')
> hs1=swh1.variables['hs']
>
> swh2=netCDF4.Dataset('filename'.'r')
> hs2=swh2.variables['hs']
>
> plt.plot(hs1,hs2,'.')
>
> Cheers,
>
> Jamie
> --
> https://mail.python.org/mailman/listinfo/python-list
>

[toc] | [prev] | [next] | [standalone]


#69460

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-04-01 01:00 +0000
Message-ID<533a0fc3$0$29994$c3e8da3$5496439d@news.astraweb.com>
In reply to#69422
On Mon, 31 Mar 2014 04:29:15 -0700, Jamie Mitchell wrote:

> I am new to python so apologies for the ignorance with this question.
> 
> How would I apply a line of best fit to a plot?

That depends on what software you are using to generate the plot. I see 
you have this line of code:

> plt.plot(hs1,hs2,'.')

but you haven't told us what plt is, where it comes from, or anything 
needed for us to answer your question.

So, start by telling us what plt is, and we may be able to tell you 
whether or not it supports lines of best fit.




-- 
Steven D'Aprano
http://import-that.dreamwidth.org/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web