#!/usr/bin/env python # coding: utf-8 # In[1]: import numpy as np import pandas as pd from lets_plot import * LetsPlot.setup_html() # In[2]: np.random.seed(42) x = np.random.uniform(1, 50, size=40) data = pd.DataFrame({'x': x, 'y': np.sin(x)}) data.head() # **geom_line()** connects points in order of the variable on the x-axis. # In[3]: ggplot(data) + geom_point(aes(x='x', y='y', color='x'), alpha=0.7, size=4) + \ scale_color_discrete() + \ theme(legend_position='none') + \ geom_line(aes(x='x', y='y'), linetype=3) # **geom_path()** connects observations in the order how they appear in data. # In[4]: ggplot(data) + geom_point(aes(x='x', y='y', color='x'), alpha=0.7, size=4) + \ scale_color_discrete() + \ theme(legend_position='none') + \ geom_path(aes(x='x', y='y'), size=0.7, linetype='dotted') # Another example to demonstrate the difference between geom_path() and geom_line(). # In[5]: a = [5, 1, 1, 5, 5, 2, 2, 4, 4, 3] b = [5, 5, 1, 1, 4, 4, 2, 2, 3, 3] snail = pd.DataFrame({'x': a, 'y': b}) # In[6]: ggplot() + geom_path(data=snail, mapping=aes(x='x', y='y'), size=2, alpha=0.7) # In[7]: ggplot() + geom_line(data=snail, mapping=aes(x='x', y='y'), size=2, alpha=0.7)