Bonjour, J'essaie de superposer deux courbes. Mais le diagramme est décalé vers la droite dans le pdf. Quand une seule courbe est tracée, elle est décalée vers la droite et partiellement visible. Quand les deux courbes sont tracées alors on ne voit rien. Cordialement. Voici le code: \documentclass{article} \usepackage[french]{babel} \usepackage{tikz} \usepackage{pgfplots} \usetikzlibrary{babel, math} \pgfplotsset{compat=1.18} \usepackage{siunitx} % \begin{document} \begin{figure} \centering \begin{tikzpicture} \begin{axis}[ xlabel={Fréquence $\omega$ [\si{\radian\per\second}]}, ylabel={Gain en dB}, xmode=log, ymode=linear, grid=both, minor grid style={gray!25}, major grid style={gray!50}, xmin=100, xmax=10000, ymin=-10, ymax=100, width=\textwidth, height=6cm, % xticklabels=\empty, legend pos=north west, ] % \pgfmathdeclarefunction{GainBode1}{1}{ \pgfmathparse{20*log10(sqrt((1-(#1/1000)^2)^2 + (2*0.5*#1/1000)^2))} } \pgfmathdeclarefunction{GainBode2}{1}{ \pgfmathparse{20*log10(sqrt((1-(#1/1000)^2)^2 + (2*0.8*#1/1000)^2))} } % \addplot[blue, line width=1.5pt, domain=100:10000, samples=100]({x}, {GainBode1(x)}); % \addlegendentry{$m=0.5$} % \addplot[red, line width=1.5pt, domain=100:10000, samples=100]({x}, {GainBode2(x)}); % \addlegendentry{$m=0.8$} % \end{axis} \end{tikzpicture} \end{figure} \end{document} |
Le problème pourrait venir de l'utilisation de pgfmathdeclarefunction. En effet j'ai simplifié l'exemple. Mon problème peut être mieux compris en mettant en commentaire, alternativement les lignes 32 et 33 (celles qui utilisent addplot). La ligne qui n'utilise pas la fonction déclarée fonctionne correctement. Celle qui utilise pgfmathdeclarefunction décale le graphique à droite. \documentclass{article} \usepackage[french]{babel} \usepackage{tikz} \usepackage{pgfplots} \usetikzlibrary{babel, math} \pgfplotsset{compat=1.18} \usepackage{siunitx} % \begin{document} \begin{figure} \centering \begin{tikzpicture} \begin{axis}[ xlabel={Fréquence $\omega$ [\si{\radian\per\second}]}, ylabel={Gain en dB}, xmode=log, ymode=linear, grid=both, minor grid style={gray!25}, major grid style={gray!50}, xmin=100, xmax=10000, ymin=-10, ymax=100, width=\textwidth, height=6cm, % xticklabels=\empty, legend pos=north west, ] % \pgfmathdeclarefunction{GaindB}{1}{ \pgfmathparse{20*log10(#1)} } % \addplot[blue, line width=1.5pt, domain=100:10000, samples=100]({x}, {GaindB(x)}); \addplot[blue, line width=1.5pt, domain=100:10000, samples=100]({x}, {20*log10(x)}); \end{axis} \end{tikzpicture} \end{figure} \end{document} |
En ajoutant simplement un "%" à la fin de la ligne pgfmathdeclarefunction{GaindB}{1}{% cela resoud le problème. |
utilisez l'environnement «code» pour un affichage correcte. Bonne nuit!