learning Matplotlib, several little questions..

i everyone i have this code :
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

# choix du style pour l'affichage des ?quations
plt.style.use('bmh')

# dimensions de la fenetre
(L,l)=(12,8)
Linch,linch=(L/2.54,l/2.54)
fig, lafigure = plt.subplots(figsize=(Linch,linch))

# choix de la police par d?faut
mpl.rcParams['font.family'] = 'STIXGeneral'
plt.rcParams["font.size"] = 10

# liste X des abscisses pour le trac?
X = np.linspace(-np.pi, np.pi, 256,endpoint=True)

# fonctions ? tracer f(X)
C,S = np.cos(X), np.sin(X)

# trac? des courbes
lafigure.plot(X, C, color="blue", linewidth=1.0, linestyle="-")
lafigure.plot(X, S, color="green", linewidth=1.0, linestyle="-")

# l?gendes
eq=(r"$\dfrac{1}{2+\frac{2}{xy}}fontof\mathit{equation}$font of text")
plt.text(0, 0.2, eq, ha='left', va='center', alpha=1)

# graduations sur les axes
plt.xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi], [r'$-\pi$', r'$-\pi/2$', r'$0$', r'$+\pi/2$', r'$+\pi$'])
plt.yticks([-1, 0, +1], [r'$-1$', r'$0$', r'$+1$'])
plt.axis('on')
lafigure.spines['right'].set_visible(True)

# segments
lafigure.plot([-3,-2,-1,0,1,2,3],[0.1,-0.1,0.1,-0.1,0.1,-0.1,0.1], color ='blue', linewidth=1, linestyle="-")

# petits ronds
t=2*np.pi/3
lafigure.scatter([t],[np.cos(t)], 50, color ='blue')
lafigure.scatter([t],[np.sin(t)], 50, color ='red')

lafigure.grid('true')
#lafigure.axis(True)

plt.savefig("bordas/Matplotlib_essais/9par6.png", dpi=288)

1) if i write alos this part of code, the resulting picture does not show the graph any longer, would you have an idea why ?
# labels sur les axes perturbe les ?chelles : ne pas utiliser
#plt.xticks(np.linspace(-4,5,9,endpoint=False))
#plt.yticks(np.linspace(-1,2,7,endpoint=True))

2) i dont really understand why sometimes i have to write plt.something, and sometimes, thougt, only lafigure.something works ???

3) i have read and read these pages :
https://matplotlib.org/users/pyplot_tutorial.html
http://python-simple.com/python-matplotlib/configuration-axes.php
http://matplotlib.org/examples/pylab_examples/spine_placement_demo.html
https://matplotlib.org/api/pyplot_api.html

and i cant manage to find how to display/hide the axis (x axis and y axis) because the word "axis" seems to be assigned to parameter the window...

thansk for your help, it is less urgent for me, i can start working without teses answers

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/20171203/c2f821e2/attachment.html>

Hello.

For point 1, just put

*plt.xticks(np.linspace(-4,5,9,endpoint=False))**
**plt.yticks(np.linspace(-1,2,7,endpoint=True))*

before saving the picture does the job on my computer.

For point 2, you have to understand that in your code you work globally
and locally on a subplot. In your case, the use of a subplot is not
necessary.

See the little simplified version of your code joined to this message
which also hides the axis.

PS 1: you should produce MWEs which are short codes showing one
identified problem.

PS 2: I hope that "les ?ditions Bordas" will cite the use of matplotlib.
:wink:

···

--
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/20171203/8fec2b9a/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example.py
Type: text/x-python-script
Size: 1338 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20171203/8fec2b9a/attachment-0001.bin>

Hi Christophe and thanks for your answers !
i work on it and come back here

PS 2: I hope that "les ?ditions Bordas" will cite the use of matplotlib. :wink:

of course you can see here :
http://mathoscope.ouvaton.org/Mathoscope.pdf
page 7 that i always thank people whose work helps me

au plaisir
Vincent

--
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/20171203/84c9c0b2/attachment.html&gt;

Hi Vincent

There are two different ?interfaces? to matplotlib. The object-oriented one (ax.plot()) and the Pyplot one (plt.plot()). The Pyplot interface is a convenience wrapper around the object oriented. So plt.plot basically just calls ax.plot using the last-used axes (plt.gca()). You can use the two syntaxes interchangeably but it gets confusing because the Pyplot doesn?t set the current axis or figure so you can easily end up putting things in the wrong axes.

Contrary to your other correspondent I pretty strongly recommend not using the Pyplot interface. The object oriented interface is more verbose but more explicit. The problem is that many examples are written in the Pyplot interface, though most of the official docs have made the switch.

I hope that helps explain the difference. I basically only use Pyplot to initialize the figure like you did: fig, ax = plt.subplots(). After that I just operate on fig and ax. Which is basically what you did. I think you didn?t find the ax.set_visible method.

Cheers Jody.

···

Sent from my iPhone

On Dec 2, 2017, at 11:27 PM, Vincent Douce Mathoscope <mathoscope at netcourrier.com> wrote:

i everyone i have this code :
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

# choix du style pour l'affichage des ?quations
plt.style.use('bmh')

# dimensions de la fenetre
(L,l)=(12,8)
Linch,linch=(L/2.54,l/2.54)
fig, lafigure = plt.subplots(figsize=(Linch,linch))

# choix de la police par d?faut
mpl.rcParams['font.family'] = 'STIXGeneral'
plt.rcParams["font.size"] = 10

# liste X des abscisses pour le trac?
X = np.linspace(-np.pi, np.pi, 256,endpoint=True)

# fonctions ? tracer f(X)
C,S = np.cos(X), np.sin(X)

# trac? des courbes
lafigure.plot(X, C, color="blue", linewidth=1.0, linestyle="-")
lafigure.plot(X, S, color="green", linewidth=1.0, linestyle="-")

# l?gendes
eq=(r"$\dfrac{1}{2+\frac{2}{xy}}fontof\mathit{equation}$font of text")
plt.text(0, 0.2, eq, ha='left', va='center', alpha=1)

# graduations sur les axes
plt.xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi], [r'\-\\pi', r'\-\\pi/2', r'0', r'\+\\pi/2', r'\+\\pi'])
plt.yticks([-1, 0, +1], [r'\-1', r'0', r'\+1'])
plt.axis('on')
lafigure.spines['right'].set_visible(True)

# segments
lafigure.plot([-3,-2,-1,0,1,2,3],[0.1,-0.1,0.1,-0.1,0.1,-0.1,0.1], color ='blue', linewidth=1, linestyle="-")

# petits ronds
t=2*np.pi/3
lafigure.scatter([t],[np.cos(t)], 50, color ='blue')
lafigure.scatter([t],[np.sin(t)], 50, color ='red')

lafigure.grid('true')
#lafigure.axis(True)

plt.savefig("bordas/Matplotlib_essais/9par6.png", dpi=288)

1) if i write alos this part of code, the resulting picture does not show the graph any longer, would you have an idea why ?
# labels sur les axes perturbe les ?chelles : ne pas utiliser
#plt.xticks(np.linspace(-4,5,9,endpoint=False))
#plt.yticks(np.linspace(-1,2,7,endpoint=True))

2) i dont really understand why sometimes i have to write plt.something, and sometimes, thougt, only lafigure.something works ???

3) i have read and read these pages :
https://matplotlib.org/users/pyplot_tutorial.html
Configuration des axes
http://matplotlib.org/examples/pylab_examples/spine_placement_demo.html
https://matplotlib.org/api/pyplot_api.html

and i cant manage to find how to display/hide the axis (x axis and y axis) because the word "axis" seems to be assigned to parameter the window...

thansk for your help, it is less urgent for me, i can start working without teses answers

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

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