0

I have created a seaborn chart in python, but the y-labes are being cut off. Here is the code:

scatter_plot = sns.scatterplot(x="Year", y="Transistors", data=trans_df.toPandas())
scatter_plot.set(title = 'Moore\'s Law ScatterPlot');
ax = plt.gca()
ax.xaxis.set_major_locator(ticker.MultipleLocator(base=10))
ax.yaxis.set_major_locator(ticker.MultipleLocator(base=10))
plt.yticks(rotation=60)
display(plt.show())

This is the chart created:

created chart

As you can see, though the x-axis has the expected label of 'Year', the y-axis label of 'Transistors' is being cut off. How do I get it to appear?

  • 1
    (Note that `display(plt.show())` does not make sense.) To show the label, you need more space on the left side. Either through `plt.subplots_adjust(left=0.3)` or `plt.tight_layout()`. – ImportanceOfBeingErnest Feb 24 '20 at 20:11
  • Hello, plt.tight_layout() worked, if you want to create an answer I can give you credit for it. display(plt.show()) is syntax specific for showing plots in databricks. –  Feb 24 '20 at 20:16
  • (Since `plt.show()` should return `None`, it's the same as `display(None)`, which will not display anything. `plt.show()` alone should be sufficient.) – ImportanceOfBeingErnest Feb 24 '20 at 20:25
  • Right, but plt.show() does not show anything in databricks, it only shows if you do display(plt.show()) –  Feb 24 '20 at 20:27
  • I see. So databricks makes use of an implementation detail here, in the hope that it will not change in the future. A correct call would be `display(ax.figure)`, or `display(plt.gcf())`. – ImportanceOfBeingErnest Feb 24 '20 at 20:38
  • This is only tangentially related, but would you please explain what '''ax.xaxis.set_major_locator(ticker.MultipleLocator(base=10))''' does? –  Feb 25 '20 at 03:48

0 Answers0