Trazar una línea suave con PyPlot


Tengo el siguiente script simple que traza un gráfico:

import matplotlib.pyplot as plt
import numpy as np

T = np.array([6, 7, 8, 9, 10, 11, 12])
power = np.array([1.53E+03, 5.92E+02, 2.04E+02, 7.24E+01, 2.72E+01, 1.10E+01, 4.70E+00])

plt.plot(T,power)
plt.show()

Como es ahora, la línea va recta de punto a punto que se ve bien, pero podría ser mejor en mi opinión. Lo que quiero es suavizar la línea entre los puntos. En Gnuplot habría trazado con smooth cplines.

¿Hay una manera fácil de hacer esto en PyPlot? He encontrado algunos tutoriales, pero todos parecen bastante complejos.

Author: Paul, 2011-03-12

2 answers

Podría usar scipy.interpolate.spline para suavizar sus datos usted mismo:

from scipy.interpolate import spline

xnew = np.linspace(T.min(),T.max(),300) #300 represents number of points to make between T.min and T.max

power_smooth = spline(T,power,xnew)

plt.plot(xnew,power_smooth)
plt.show()

Antes: captura de pantalla 1

Después: captura de pantalla 2

 108
Author: Olivier Verdier,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-03 20:35:34

Supongo que quiere decir ajuste de curvay no anti-aliasing desde el contexto de su pregunta. PyPlot no tiene ningún soporte incorporado para esto, pero puede implementar fácilmente algunos ajustes básicos de curva usted mismo, como el código visto aquí, o si está utilizando GuiQwt, tiene un módulo de ajuste de curva . (Probablemente también podrías robar el código de SciPy para hacer esto también).

 6
Author: Nick Bastin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-03-12 17:04:23