0

I have almost a nice plot but there are issues. The first one: x label doesn't show up. The second issue: I can't put the name of second line in legend. I have only one name (Close) and I need also 'KGHM'.

fig, ax = plt.subplots()
ax.plot(x,y)

ax2 = ax.twinx()
ax2.plot(x1,y1, 'y-')

myFmt = DateFormatter("%d-%m-%y")
ax.xaxis.set_major_formatter(myFmt)

fig.autofmt_xdate()
plt.tight_layout()

plt.xlabel('PLN',size=10)
plt.ylabel('Points',size=10)
plt.title('KGHM')
ax.grid(True)

ax.legend()

plt.show()

enter image description here

Thanks for help !

Tmiskiewicz
  • 389
  • 1
  • 11
  • 2
    The reason for no xlabel is that you don't define any x label in your code. The second question has just been [asked](https://stackoverflow.com/questions/54332485/only-one-dataname-shows-in-the-legend) a few minutes ago. – ImportanceOfBeingErnest Jan 23 '19 at 19:43
  • Thank you for help with the second question. But as you can see a change xlabel in my cold and it's not working still – Tmiskiewicz Jan 23 '19 at 19:51
  • Yes, do it *before* defining the twin axes, or use object oriented style, `ax.set_xlabel("bla")` to set the label for the axes for which you want it. – ImportanceOfBeingErnest Jan 23 '19 at 20:08
  • I do it but it didn't help and I have the message: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect. warnings.warn("This figure includes Axes that are not compatible " – Tmiskiewicz Jan 23 '19 at 20:13
  • Perhaps there is a issue that there is not enough place... I don't know – Tmiskiewicz Jan 23 '19 at 20:14
  • ok, I got it. Thanks for help. In the end ax.set_xlabel("bla") did the work :) – Tmiskiewicz Jan 23 '19 at 20:37

0 Answers0