Python Forum
Overlay two lines on a single seaborn plot - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Overlay two lines on a single seaborn plot (/thread-683.html)



Overlay two lines on a single seaborn plot - pemfir - Oct-28-2016

Quote:issue i am facing is that when i want to plot two datasets into a single seaborn graph, the graph does not maintain the correct x-axis from each individual dataset. The toy example is shown below. Please help me while not changing the general structure of the code. If there is a quick fix to get the x-axis labels work correctly, I greatly appreciate to know it.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sb
import datetime
code below creates two datasets. In reality, data comes different sources, so please do not change the way data is. Note that dates are no overlapping in each dataset
dataset1 = pd.DataFrame({'Dates' : [datetime.date(2016,10,01) + datetime.timedelta(days = i) for i in range(0,20)],
               'values' : np.ones(20)} )

dataset2 = pd.DataFrame({'Dates' : [datetime.date(2016,11,01) + datetime.timedelta(days = i) for i in range(0,20)],
               'values' : np.ones(20)*2} )
When i plot them together into a single graph, the x-axis is messed up. The graphs are drawn on top of each other but the dates (x-axis) are non-overlapping in each dataset
%matplotlib inline
fig, ax = plt.subplots()
sb.pointplot(x='Dates', y='values', data=dataset1, ax=ax, color='b')
sb.pointplot(x='Dates', y='values', data=dataset2, ax=ax, color='r')
labels = ax.get_xticklabels() 
ax.set_xticklabels(labels, rotation=-30)
sb.plt.show()



RE: Overlay two lines on a single seaborn plot - Ofnuts - Oct-28-2016

From all the documentation I see about the seaborn package, you should use one single call to pointplot with a data set that contains the two series.