Re: [Tutor] New plot over the old graph

2011-12-01 Thread stm atoc
I appreciated for the accurate response.
I used step by step and  it is running now.

Thank you very much for your advice and guidance,

Sue


On Thu, Dec 1, 2011 at 10:01 PM, Andreas Perstinger
 wrote:
> On 2011-12-01 19:20, stm atoc wrote:
>>
>> Thanks for all information/websites and advice. Yes the graph is
>> exactly like the one you mentioned. Also, I would like to have them in
>> one not two, but I think since the dimension of the x and y are not
>> same, I have no choice.
>>
>>  What I like to do now is comparing 2 (later 3 or more) different sets
>> of data, e.g. comparison among Conc[1] with sets
>>
>> I have changed the script like this:
>>
>> with open("ourtest_out.list", "r") as f:
>>    z = numpy.array([float(v) for v in f.readline().split()[1:]])
>>
>> a1 = numpy.loadtxt("ourtest_out1.list", skiprows=3)
>> a2 = numpy.loadtxt("ourtest_out2.list", skiprows=3)
>> a3 = numpy.loadtxt("ourtest_out3.list", skiprows=3)
>>
>> N = 100
>>
>> Conc1 = a1[0:, N+1:] #base case
>> Conc2 = a2[0:, N+1:] # Ydw=0.1
>> Conc3 = a3[0:, N+1:] # nuh=0.01
>> lw = 2.0 #linewidth
>
>
> You aren't using "lw" so it doesn't make sense to define it.
>
>> dpi = 96
>> figure(figsize=(10,6),dpi=dpi)
>
>
> I prefer to not clutter up the namespace with "star imports" (from pylabs
> import *) but it's your choice.
>
>>
>> pyplot.subplot(111)
>
>
> If you just use one graph/figure this call is unnecessary.
>
>
>> pyplot.plot(Conc1[1], z)
>> pyplot.plot(Conc2[1], z)
>> pyplot.plot(Conc3[1], z)
>> pyplot.xlim(0,1)
>>
>> plt.xlabel('Conc')
>> plt.ylabel('z')
>
>
> I assume you've got these lines from the tutorial. But there they are using
> the following import:
>
> import matplotlib.pyplot as plt
>
> I've used
>
> import matplotlib.pyplot as pyplot
>
> so you have to decide which name you want to use (You can't mix both).
>
> In general, if you just use
>
> import matplotlib.pyplot
>
> you would have to use always the full name:
>
> matplotlib.pyplot.xlabel('Conc')
>
> But with the "as"-keyword you can choose, which name gets imported into the
> namespace.
>
> If you have problems understanding imports and namespaces look at Alan's
> tutorial:
> http://www.freenetpages.co.uk/hp/alan.gauld/tutfunc.htm (section "Using
> Modules")
> http://www.freenetpages.co.uk/hp/alan.gauld/tutname.htm (about Namespaces)
>
>
>>
>> pyplot.grid(True)
>> show()
>> savefig('Conc.png')
>
>
> You should call "savefig" before "show" because in non-interactive mode
> (calling the script from the commandline) "show" will block all figures
> until they are closed. So after "show" there won't be any figures left and
> "savefig" will write an empty figure to the file.
>
>
>> close()
>>
>> This can give me the comparison in one graph, I suppose.
>> Now, first I like to know if this is a fine/logical script. otherwise
>> I would like to know about probably a better way to write it with less
>> lines!
>
>
> You could write the whole script in a more object-oriented style where you
> create a figure-instance and then set the attributes you want instead of
> calling all the functions. But for the beginning it's ok.
>
>
>> and second, when I do plot, each grid between x or y axis, has a
>> thickness of 0.2. what I like do is to change it to 0.1 grid . So, I
>> couldn't find it through matplotlib website (at least with my
>> searching. Would it be possible helping me about?
>
>
> You set the scale with the "xticks"-function (or the corresponding
> "yticks"):
> http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.xticks
>
> So in your case you could use
>
> pyplot.xticks(numpy.arange(0, 1.1, 0.1))
>
>
> Bye, Andreas
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New plot over the old graph

2011-12-01 Thread Andreas Perstinger

On 2011-12-01 19:20, stm atoc wrote:

Thanks for all information/websites and advice. Yes the graph is
exactly like the one you mentioned. Also, I would like to have them in
one not two, but I think since the dimension of the x and y are not
same, I have no choice.

  What I like to do now is comparing 2 (later 3 or more) different sets
of data, e.g. comparison among Conc[1] with sets

I have changed the script like this:

with open("ourtest_out.list", "r") as f:
z = numpy.array([float(v) for v in f.readline().split()[1:]])

a1 = numpy.loadtxt("ourtest_out1.list", skiprows=3)
a2 = numpy.loadtxt("ourtest_out2.list", skiprows=3)
a3 = numpy.loadtxt("ourtest_out3.list", skiprows=3)

N = 100

Conc1 = a1[0:, N+1:] #base case
Conc2 = a2[0:, N+1:] # Ydw=0.1
Conc3 = a3[0:, N+1:] # nuh=0.01
lw = 2.0 #linewidth


You aren't using "lw" so it doesn't make sense to define it.


dpi = 96
figure(figsize=(10,6),dpi=dpi)


I prefer to not clutter up the namespace with "star imports" (from 
pylabs import *) but it's your choice.




pyplot.subplot(111)


If you just use one graph/figure this call is unnecessary.


pyplot.plot(Conc1[1], z)
pyplot.plot(Conc2[1], z)
pyplot.plot(Conc3[1], z)
pyplot.xlim(0,1)

plt.xlabel('Conc')
plt.ylabel('z')


I assume you've got these lines from the tutorial. But there they are 
using the following import:


import matplotlib.pyplot as plt

I've used

import matplotlib.pyplot as pyplot

so you have to decide which name you want to use (You can't mix both).

In general, if you just use

import matplotlib.pyplot

you would have to use always the full name:

matplotlib.pyplot.xlabel('Conc')

But with the "as"-keyword you can choose, which name gets imported into 
the namespace.


If you have problems understanding imports and namespaces look at Alan's 
tutorial:
http://www.freenetpages.co.uk/hp/alan.gauld/tutfunc.htm (section "Using 
Modules")

http://www.freenetpages.co.uk/hp/alan.gauld/tutname.htm (about Namespaces)



pyplot.grid(True)
show()
savefig('Conc.png')


You should call "savefig" before "show" because in non-interactive mode 
(calling the script from the commandline) "show" will block all figures 
until they are closed. So after "show" there won't be any figures left 
and "savefig" will write an empty figure to the file.



close()

This can give me the comparison in one graph, I suppose.
Now, first I like to know if this is a fine/logical script. otherwise
I would like to know about probably a better way to write it with less
lines!


You could write the whole script in a more object-oriented style where 
you create a figure-instance and then set the attributes you want 
instead of calling all the functions. But for the beginning it's ok.



and second, when I do plot, each grid between x or y axis, has a
thickness of 0.2. what I like do is to change it to 0.1 grid . So, I
couldn't find it through matplotlib website (at least with my
searching. Would it be possible helping me about?


You set the scale with the "xticks"-function (or the corresponding 
"yticks"):

http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.xticks

So in your case you could use

pyplot.xticks(numpy.arange(0, 1.1, 0.1))

Bye, Andreas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New plot over the old graph

2011-12-01 Thread stm atoc
Thanks for all information/websites and advice. Yes the graph is
exactly like the one you mentioned. Also, I would like to have them in
one not two, but I think since the dimension of the x and y are not
same, I have no choice.

 What I like to do now is comparing 2 (later 3 or more) different sets
of data, e.g. comparison among Conc[1] with sets

I have changed the script like this:

with open("ourtest_out.list", "r") as f:
   z = numpy.array([float(v) for v in f.readline().split()[1:]])

a1 = numpy.loadtxt("ourtest_out1.list", skiprows=3)
a2 = numpy.loadtxt("ourtest_out2.list", skiprows=3)
a3 = numpy.loadtxt("ourtest_out3.list", skiprows=3)

N = 100

Conc1 = a1[0:, N+1:] #base case
Conc2 = a2[0:, N+1:] # Ydw=0.1
Conc3 = a3[0:, N+1:] # nuh=0.01
lw = 2.0 #linewidth
dpi = 96
figure(figsize=(10,6),dpi=dpi)

pyplot.subplot(111)
pyplot.plot(Conc1[1], z)
pyplot.plot(Conc2[1], z)
pyplot.plot(Conc3[1], z)
pyplot.xlim(0,1)

plt.xlabel('Conc')
plt.ylabel('z')

pyplot.grid(True)
show()
savefig('Conc.png')
close()

This can give me the comparison in one graph, I suppose.
Now, first I like to know if this is a fine/logical script. otherwise
I would like to know about probably a better way to write it with less
lines!
and second, when I do plot, each grid between x or y axis, has a
thickness of 0.2. what I like do is to change it to 0.1 grid . So, I
couldn't find it through matplotlib website (at least with my
searching. Would it be possible helping me about?  I am  new at python
and a beginner and I do have learn while I work with it...

Thanks in advance,
Sue


On Thu, Dec 1, 2011 at 6:25 PM, Andreas Perstinger
 wrote:
> On 2011-12-01 14:30, stm atoc wrote:
>>
>> With your help, I have a good script from the previous discussion:
>>
>> **
>> from pylab import *
>
>
> Have you used MATLAB before and are used to its syntax? In general "star
> imports" (from xxx import *) are a bad practice and IMHO should be avoided.
>
>
>> import numpy
>> import matplotlib.pyplot as pyplot
>> import matplotlib.mlab as mlab
>
>
> These imports are unnecessary if you use the first line because "pylab"
> imports everything from "numpy" and "matplotlib" into a single namespace. So
> either use just the first line (not recommended) or the following line
> (recommended).
>
> See also
> http://matplotlib.sourceforge.net/faq/usage_faq.html#matplotlib-pylab-and-pyplot-how-are-they-related
> and
> http://matplotlib.sourceforge.net/faq/usage_faq.html#coding-styles
>
> BTW: Why do you import "mlab" when you don't use it?
>
>
>> with open("ourtest_out.list", "r") as f:
>>    z = numpy.array([float(v) for v in f.readline().split()[1:]])
>>
>> a = numpy.loadtxt("ourtest_out.list", skiprows=3)
>> N = 100
>> Conc = a[0:, N+1:]
>> print len(Conc[0]) == len(z)
>
>
> This line was just for testing. You can delete it without any consequences.
>
>
>
>> figure()
>>
>> pyplot.plot(Conc[0],z,'r-',label='initial')
>> pyplot.plot(Conc[1],z,'b-',label='after 20s')
>>
>> show()
>
>
> Isn't that what you want? You are plotting all your data in one graph. There
> is a straight red line on the left side and a falling blue line from left to
> right.
>
>
>> *
>>
>> I have tried to make subplot for this case as follows:
>>
>> pyplot.subplot(111)
>> pyplot.plot(Conc[0],z,'r-',label='initial')
>> pyplot.plot(Conc[1],z,'b-',label='after 20s')
>
>
> Here you are creating a subplot with 1 plot each row and 1 plot each column,
> in other words you do the same as above (creating just 1 plot). If you want
> to have for example 4 plots in the same window with 2 each row and 2 each
> column you have to use
>
> pyplot.subplot(221)
>
> After plotting all the data in this first "axes" you have to switch to the
> next one:
>
> pyplot.subplot(222)
>
> Have you already read the matplotlib-tutorial:
> http://matplotlib.sourceforge.net/users/pyplot_tutorial.html
>
>
>> However, I am not sure how to add new data over this to make a graph
>> including both new and old data simultaneously.
>
>
> As I've said before: You are already plotting all data in one graph.
> Don't you get two different lines?
>
> Bye, Andreas
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New plot over the old graph

2011-12-01 Thread Andreas Perstinger

On 2011-12-01 14:30, stm atoc wrote:

With your help, I have a good script from the previous discussion:

**
from pylab import *


Have you used MATLAB before and are used to its syntax? In general "star 
imports" (from xxx import *) are a bad practice and IMHO should be avoided.



import numpy
import matplotlib.pyplot as pyplot
import matplotlib.mlab as mlab


These imports are unnecessary if you use the first line because "pylab" 
imports everything from "numpy" and "matplotlib" into a single 
namespace. So either use just the first line (not recommended) or the 
following line (recommended).


See also
http://matplotlib.sourceforge.net/faq/usage_faq.html#matplotlib-pylab-and-pyplot-how-are-they-related
and
http://matplotlib.sourceforge.net/faq/usage_faq.html#coding-styles

BTW: Why do you import "mlab" when you don't use it?


with open("ourtest_out.list", "r") as f:
z = numpy.array([float(v) for v in f.readline().split()[1:]])

a = numpy.loadtxt("ourtest_out.list", skiprows=3)
N = 100
Conc = a[0:, N+1:]
print len(Conc[0]) == len(z)


This line was just for testing. You can delete it without any consequences.



figure()

pyplot.plot(Conc[0],z,'r-',label='initial')
pyplot.plot(Conc[1],z,'b-',label='after 20s')

show()


Isn't that what you want? You are plotting all your data in one graph. 
There is a straight red line on the left side and a falling blue line 
from left to right.



*

I have tried to make subplot for this case as follows:

pyplot.subplot(111)
pyplot.plot(Conc[0],z,'r-',label='initial')
pyplot.plot(Conc[1],z,'b-',label='after 20s')


Here you are creating a subplot with 1 plot each row and 1 plot each 
column, in other words you do the same as above (creating just 1 plot). 
If you want to have for example 4 plots in the same window with 2 each 
row and 2 each column you have to use


pyplot.subplot(221)

After plotting all the data in this first "axes" you have to switch to 
the next one:


pyplot.subplot(222)

Have you already read the matplotlib-tutorial:
http://matplotlib.sourceforge.net/users/pyplot_tutorial.html


However, I am not sure how to add new data over this to make a graph
including both new and old data simultaneously.


As I've said before: You are already plotting all data in one graph.
Don't you get two different lines?

Bye, Andreas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor