0

Why my lineplot doesn't begin with barplot? When I put only lineplot with ax2.set_xticklabels I got UserWarning: FixedFormatter should only be used together with FixedLocator. How to deal with this?

[ax1, ax2] = plt.subplots(figsize=(10, 7))

x = Melbourne2010['Month']

ax1 = sns.barplot(x = x, y = "Rainfall", data = Melbourne2010, 
                 estimator = sum, #moze mean
                 ci = None, 
                 color = 'Blue')

ax1.tick_params(axis='y', labelcolor='Blue')
ax1.set_title('Climate graph for Melbourne in 2010', fontsize = 20)
ax1.set_ylabel('Totall R (mm)', color = 'Blue', fontsize = 13)
ax1.set_xlabel('Month', fontsize = 13)
ax1.set_xticklabels(('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'))
ax1.grid(None)

ax2 = ax1.twinx()
ax2 = sns.lineplot(x = x, y = "MaxTemp", data = Melbourne2010,
                   ci = None,
                   color = "red")

ax2.tick_params(axis = 'y', labelcolor = 'red')
ax2.set_ylabel("Maximum Temperature (0C)", color = 'red', fontsize = 13)

ax2 = plt.gca()
ax2.set_ylim([0, 50])

ax2.grid(None)

plt.show()

enter image description here

Mr. T
  • 11,141
  • 9
  • 27
  • 51
Aga98
  • 1
  • Your example code forgets to set test data for `x` and `y`. There are quite some strange assignments in your code. The problem with the alignment comes from `barplot` creating categorical axes (internally numbered 0,1,2,... even if the x-values would be numeric to start with). You could try `pointplot` (instead of `lineplot`) which also uses a categorical x-axis. To set the labels, you could try `ax1.set_xticks(range(12))` before `ax1.set_xticklabels(('Jan', 'Feb', 'Mar', ...))` – JohanC Feb 07 '22 at 22:38

0 Answers0