[Matplotlib-users] automatic list of r'$2$'...

Christophe BAL (via GMAIL) projetmbc at gmail.com
Sat Dec 23 16:34:59 EST 2017


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("$".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$']
>> 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
>> https://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 list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users

-- 
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>


More information about the Matplotlib-users mailing list