0

I'm trying to plot two data frames in one graph with 30 days data on the x axis. However most of the xaxis ticks are not showing and their spacing is off. How can I show the full 30 ticks?

Here is the code:

fig = plt.figure(figsize=(10,8))
g1 = fig.add_subplot(211)
g1 = sns.lineplot(x=unique_cust.index, y=unique_cust['msisdn'], data=unique_cust, color="b", marker='o')
g1.set_ylabel("Unique Customers")
g1.yaxis.label.set_color('blue')
g1.set_xticklabels(size=8, rotation=30, labels=unique_cust.index.strftime("%d-%b"))
g2=g1.twinx()

g2 = sns.lineplot(x=unique_merch.index, y=unique_merch['merchant'], data=unique_merch, color="r", marker='^')
g2.set_ylabel("Unique Merchants")
g2.yaxis.label.set_color('red')
g2.set_xticklabels(size=8, rotation=30, labels=unique_merch.index.strftime("%d-%b"))
g1.grid()
plt.show()

Additionally: how can I change the format of the y axis to have a comma every thousand digits? and how can I keep the xasix label from overlapping the graph below it (using 'tight' spacing doesn't work)?

enter image description here

ReinForce
  • 101
  • 2
  • 6
  • 11
  • 1
    You forgot to specify *where* the ticklabels should appear (`ax.set_xticks()`). Also, if you want to label each and every coordinate, labels would probably overlap and become unreadable. – ImportanceOfBeingErnest Dec 07 '18 at 19:13
  • g2.set_xticks(unique_merch.index) for label in g1.xaxis.get_ticklabels()[1::2]: label.set_visible(False) Using this I've got the tick labels set but the spacing is still off. Look at the spacing between the last 3 points. – ReinForce Dec 07 '18 at 19:26
  • Probably a useful read: [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – ImportanceOfBeingErnest Dec 07 '18 at 19:37

0 Answers0