automatic list of r'$2$'...

hi
i try this :
'''
Lx,x,Ly,y=[],xmin,[],ymin
Lrx,Lry=[],[]
while (x<=xmax):
    Lx.append(x)
    Lrx.append("$".join(["r'",str(x),"'"]))
    x+=1
while (y<=ymax):
    Ly.append(y)
    y+=1
'''
but it creates a Lrx list like this :
["r'$-2.5$'", "r'$-1.5$'", "r'$-0.5$'", "r'$0.5$'", "r'$1.5$'", "r'$2.5$'"]
and i want to obtain
[r'$-2.5$', r'$-1.5$', r'$-0.5$', r'$0.5$', r'$1.5$', r'$2.5$']

i guess that r is an operator to deal with the $..$ expressions but not understand how to fix my definition

thanks for your help

Vincent

        ???
                  Vincent Douce
               :=: Mathoscope :=:
             http://mathoscope.xyz/>
                 06?13?11?07?26
          Bagn?res de Bigorre 65200

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20171213/323e6812/attachment-0001.html>

Well, isn't

Lx = np.arange(xmin, xmax + 1)
Lrx = [r"${}$".format(val) for val in Lx]  # aka 'list comprehension'

producing what you are looking for?

Adrien

PS: in the long term, another (more global) approach might be to
leverage Matplotlib's formatting capabilities like the ones introduced here:
http://matplotlib.org/gallery/ticks_and_spines/tick-formatters.html
or
https://matplotlib.org/tutorials/text/usetex.html
and then simply define the ticks (meaning their value) that you want.

···

On 12/13/2017 10:52 AM, Vincent Douce Mathoscope wrote:

hi
i try this :
'''
Lx,x,Ly,y=,xmin,,ymin
Lrx,Lry=,
while (x<=xmax):
? ? Lx.append(x)
? ? Lrx.append("&quot;\.join\(\[&quot;r&#39;&quot;,str\(x\),&quot;&#39;&quot;\]\)\) ? ? x\+=1 while \(y&lt;=ymax\): ? ? Ly\.append\(y\) ? ? y\+=1 &#39;&#39;&#39; but it creates a Lrx list like this : \[&quot;r&#39;-2.5$'", "r'\-1\.5'", "r'\-0\.5'", "r'0\.5'", "r'1\.5'", "r'2\.5'"]
and i want to obtain
[r'\-2\.5', r'\-1\.5', r'\-0\.5', r'0\.5', r'1\.5', r'2\.5']

i guess that r is an operator to deal with the \.\. expressions but not
understand how to fix my definition

thanks for your help

Vincent

? ? ? ? ???
? ? ? ? ? ? ? ? ? Vincent Douce
? ? ? ? ? ? ? ?:=: Mathoscope?:=:
http://mathoscope.xyz
? ? ? ? ? ? ? ? ?06?13?11?07?26
? ? ? ? ? Bagn?res de Bigorre 65200

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

Le mercredi 13 d?cembre 2017, Vincent Douce Mathoscope a ?crit :

hi
i try this :
'''
Lx,x,Ly,y=,xmin,,ymin
Lrx,Lry=,
while (x<=xmax):
    Lx.append(x)
    Lrx.append("&quot;\.join\(\[&quot;r&#39;&quot;,str\(x\),&quot;&#39;&quot;\]\)\) &nbsp;&nbsp;&nbsp;&nbsp;x\+=1 while \(y&lt;=ymax\): &nbsp;&nbsp;&nbsp;&nbsp;Ly\.append\(y\) &nbsp;&nbsp;&nbsp;&nbsp;y\+=1 &#39;&#39;&#39; but it creates a Lrx list like this : \[&quot;r&#39;-2.5$'", "r'\-1\.5'", "r'\-0\.5'", "r'0\.5'", "r'1\.5'",
"r'2\.5'"]
and i want to obtain
[r'\-2\.5', r'\-1\.5', r'\-0\.5', r'0\.5', r'1\.5', r'2\.5']

My suggestion

import numpy as np
tmpx = [(x, r'$%s' % x) for x in np.arange(xmin, xmax, 1)]
Lx, Lrx = zip(*tmpx)

Idem for the y stuff.
If you prefer to keep the while loop, change the Lrx line to
Lrx.append(r"%s" %x)
or
Lrx.append(r"\{\}".format(x))
Note that you can add format specification in both solutions.

thanks Fabrice
the problems seems to be :
i get for Lrx :
'$0', '$1', '$2'
instead of
r'$0', r'$1', r'$2'
the "r" disappears
as the r is not in the chain is seems not to be considered by python as an element to keep ?
Vincent

Le 13 d?c. 2017 ? 20:42, Fabrice Silva <silva at lma.cnrs-mrs.fr> a ?crit :

Le mercredi 13 d?cembre 2017, Vincent Douce Mathoscope a ?crit :

hi
i try this :
'''
Lx,x,Ly,y=,xmin,,ymin
Lrx,Lry=,
while (x<=xmax):
   Lx.append(x)
   Lrx.append("&quot;\.join\(\[&quot;r&#39;&quot;,str\(x\),&quot;&#39;&quot;\]\)\) &nbsp;&nbsp;&nbsp;x\+=1 while \(y&lt;=ymax\): &nbsp;&nbsp;&nbsp;Ly\.append\(y\) &nbsp;&nbsp;&nbsp;y\+=1 &#39;&#39;&#39; but it creates a Lrx list like this : \[&quot;r&#39;-2.5$'", "r'\-1\.5'", "r'\-0\.5'", "r'0\.5'", "r'1\.5'",
"r'2\.5'"]
and i want to obtain
[r'\-2\.5', r'\-1\.5', r'\-0\.5', r'0\.5', r'1\.5', r'2\.5']

My suggestion

import numpy as np
tmpx = [(x, r'$%s' % x) for x in np.arange(xmin, xmax, 1)]
Lx, Lrx = zip(*tmpx)

Idem for the y stuff.
If you prefer to keep the while loop, change the Lrx line to
Lrx.append(r"%s" %x)
or
Lrx.append(r"\{\}".format(x))
Note that you can add format specification in both solutions.

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

        ???
                  Vincent Douce
               :=: Mathoscope :=:
             http://mathoscope.xyz
                 06?13?11?07?26
          Bagn?res de Bigorre 65200

Hello.

One question: why do you use raw strings ?

One suggestion: with Python 3.6, you can use *fr"\{x\}"*? or simply
*f"\{x\}"*? if you don't really need raw strings.

Le 23/12/2017 ? 22:01, Vincent Douce Mathoscope a ?crit?:

···

thanks Fabrice
the problems seems to be :
i get for Lrx :
'$0', '$1', '$2'
instead of
r'$0', r'$1', r'$2'
the "r" disappears
as the r is not in the chain is seems not to be considered by python as an element to keep ?
Vincent

Le 13 d?c. 2017 ? 20:42, Fabrice Silva <silva at lma.cnrs-mrs.fr> a ?crit :

Le mercredi 13 d?cembre 2017, Vincent Douce Mathoscope a ?crit :

hi
i try this :
'''
Lx,x,Ly,y=,xmin,,ymin
Lrx,Lry=,
while (x<=xmax):
    Lx.append(x)
    Lrx.append("&quot;\.join\(\[&quot;r&#39;&quot;,str\(x\),&quot;&#39;&quot;\]\)\) &nbsp;&nbsp;&nbsp;&nbsp;x\+=1 while \(y&lt;=ymax\): &nbsp;&nbsp;&nbsp;&nbsp;Ly\.append\(y\) &nbsp;&nbsp;&nbsp;&nbsp;y\+=1 &#39;&#39;&#39; but it creates a Lrx list like this : \[&quot;r&#39;-2.5$'", "r'\-1\.5'", "r'\-0\.5'", "r'0\.5'", "r'1\.5'",
"r'2\.5'"]
and i want to obtain
[r'\-2\.5', r'\-1\.5', r'\-0\.5', r'0\.5', r'1\.5', r'2\.5']

My suggestion

import numpy as np
tmpx = [(x, r'$%s' % x) for x in np.arange(xmin, xmax, 1)]
Lx, Lrx = zip(*tmpx)

Idem for the y stuff.
If you prefer to keep the while loop, change the Lrx line to
Lrx.append(r"%s" %x)
or
Lrx.append(r"\{\}".format(x))
Note that you can add format specification in both solutions.

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

         ???
                   Vincent Douce
                :=: Mathoscope :=:
              http://mathoscope.xyz
                  06?13?11?07?26
           Bagn?res de Bigorre 65200

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

--
Christophe BAL
Enseignant Agr?g? de Math?matiques
Programmeur Python Amateur

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20171223/0d613ee0/attachment.html&gt;

The 'r' prefix tells python to not try an interpret any escape sequences
(such at \t for 'tab' and '\n' for a new line) as escape sequences. This
is part of the core python language, not Matplotlib or latex specific!

If you did not use raw string and wanted to use ? (theta) as '\\theta`
python would go 'Ah ha! they asked for the string "&quot; &quot;&lt;TAB&gt; &quot;h&quot; &quot;e&quot; &quot;t&quot; &quot;a&quot; &quot;" ' which is not what you wanted. To get around this you can either
do "\\\\theta" or r"\\theta.

Using raw strings is probably the better option as future versions of
python will fail on unknown escape sequences so _every_ \ in your latex
would have to be \\.

Tom

···

On Sat, Dec 23, 2017 at 4:39 PM Christophe BAL (via GMAIL) < projetmbc at gmail.com> wrote:

Hello.

One question: why do you use raw strings ?

One suggestion: with Python 3.6, you can use *fr"\{x\}"* or simply
*f"\{x\}"* if you don't really need raw strings.

Le 23/12/2017 ? 22:01, Vincent Douce Mathoscope a ?crit :

thanks Fabrice
the problems seems to be :
i get for Lrx :
'$0', '$1', '$2'
instead of
r'$0', r'$1', r'$2'
the "r" disappears
as the r is not in the chain is seems not to be considered by python as an element to keep ?
Vincent

Le 13 d?c. 2017 ? 20:42, Fabrice Silva <silva at lma.cnrs-mrs.fr> <silva at lma.cnrs-mrs.fr> a ?crit :

Le mercredi 13 d?cembre 2017, Vincent Douce Mathoscope a ?crit :

hi
i try this :
'''
Lx,x,Ly,y=,xmin,,ymin
Lrx,Lry=,
while (x<=xmax):
   Lx.append(x)
   Lrx.append("&quot;\.join\(\[&quot;r&#39;&quot;,str\(x\),&quot;&#39;&quot;\]\)\) &nbsp;&nbsp;&nbsp;x\+=1 while \(y&lt;=ymax\): &nbsp;&nbsp;&nbsp;Ly\.append\(y\) &nbsp;&nbsp;&nbsp;y\+=1 &#39;&#39;&#39; but it creates a Lrx list like this : \[&quot;r&#39;-2.5$'", "r'\-1\.5'", "r'\-0\.5'", "r'0\.5'", "r'1\.5'",
"r'2\.5'"]
and i want to obtain
[r'\-2\.5', r'\-1\.5', r'\-0\.5', r'0\.5', r'1\.5', r'2\.5']

My suggestion

import numpy as np
tmpx = [(x, r'$%s' % x) for x in np.arange(xmin, xmax, 1)]
Lx, Lrx = zip(*tmpx)

Idem for the y stuff.
If you prefer to keep the while loop, change the Lrx line to
Lrx.append(r"%s" %x)
or
Lrx.append(r"\{\}".format(x))
Note that you can add format specification in both solutions.

_______________________________________________
Matplotlib-users mailing listMatplotlib-users at python.orghttps://mail.python.org/mailman/listinfo/matplotlib-users

        ???
                  Vincent Douce
               :=: Mathoscope :=:
             http://mathoscope.xyz
                 06?13?11?07?26
          Bagn?res de Bigorre 65200

_______________________________________________
Matplotlib-users mailing listMatplotlib-users at python.orghttps://mail.python.org/mailman/listinfo/matplotlib-users

--
Christophe BAL
Enseignant Agr?g? de Math?matiques
Programmeur Python Amateur

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180420/b93e3b64/attachment-0001.html&gt;