Oct-28-2016, 04:38 PM
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 datetimecode 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()