Python Forum
Overlay two lines on a single seaborn plot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Overlay two lines on a single seaborn plot
#1
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()
Reply


Messages In This Thread
Overlay two lines on a single seaborn plot - by pemfir - Oct-28-2016, 04:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Seaborn not displaying the specified n bins russellm10 0 629 Jun-28-2023, 02:51 AM
Last Post: russellm10
  Seaborn and Pandas russellm10 0 1,329 Nov-20-2021, 04:01 PM
Last Post: russellm10
  Reset seaborn ju21878436312 2 5,200 Jun-15-2021, 09:31 AM
Last Post: ju21878436312
  Seaborn regplot regression equation? Cricri 2 6,798 Jun-09-2020, 01:32 PM
Last Post: Cricri
  Seaborn clustermap clustered data YoYo1975 2 2,394 Feb-05-2020, 09:08 AM
Last Post: YoYo1975
  Error when installing Seaborn package using pip chawkins 3 5,681 Jul-16-2018, 12:12 AM
Last Post: Larz60+
  Remove internal lines donut plot matplotlib diego_last 5 6,381 Dec-14-2017, 04:05 PM
Last Post: diego_last
  Why can't I import seaborn module? Athenaeum 1 6,523 Dec-09-2017, 08:40 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020