Simple line plots using seaborn
Since seaborn also uses matplotlib to do its plotting you can easily combine the two. If you only want to adopt the styling of seaborn the set_style
function should get you started:
import matplotlib.pyplot as pltimport numpy as npimport seaborn as snssns.set_style("darkgrid")plt.plot(np.cumsum(np.random.randn(1000,1)))plt.show()
Result:
It's possible to get this done using seaborn.lineplot()
but it involves some additional work of converting numpy arrays to pandas dataframe. Here's a complete example:
# importsimport seaborn as snsimport numpy as npimport pandas as pd# inputsIn [41]: num = np.array([1, 2, 3, 4, 5])In [42]: sqr = np.array([1, 4, 9, 16, 25])# convert to pandas dataframeIn [43]: d = {'num': num, 'sqr': sqr}In [44]: pdnumsqr = pd.DataFrame(d)# plot using lineplotIn [45]: sns.set(style='darkgrid')In [46]: sns.lineplot(x='num', y='sqr', data=pdnumsqr)Out[46]: <matplotlib.axes._subplots.AxesSubplot at 0x7f583c05d0b8>
And we get the following plot:
Yes, you can do the same in Seaborn directly. This is done with tsplot() which allows either a single array as input, or two arrays where the other is 'time' i.e. x-axis.
import seaborn as snsdata = [1,5,3,2,6] * 20time = range(100)sns.tsplot(data, time)