1

I have plotted a stack of 9 plots and have labeled the y axis. The plots are fine but the label on the y axis is not aligned properly. When I try the following code

plt.set_ylabel('CF (E-14 )',size=15)
plt.yaxis.get_label().set_verticalalignment("baseline")

this is the error i get

AttributeError                            Traceback (most recent call last)
<ipython-input-140-87dca852bea2> in <module>()
    100 
    101 
--> 102 fit_data()

<ipython-input-140-87dca852bea2> in fit_data()
     86 
     87     plt.xlabel('M0',size=15)
---> 88     plt.set_ylabel('CF (E-14 )',size=15)
     89     plt.yaxis.get_label().set_verticalalignment("baseline")
     90 

AttributeError: module 'matplotlib.pyplot' has no attribute 'set_ylabel'

I want to align the label on the y axis. All the stacked plots have a common x axis. This is a sample plot image that I need to plot sample. This was done by someone else on another software. I am plotting it on jupyter-notebook. I am not sure how to align the label on the y-axis

If set label is not used, the label for the y axis in below the plots. I have modified the code and this is the how it appears. plot

plt.xlabel('M0',size=15)
plt.ylabel('label for y axisCF(E-14)',size=15,va='center', rotation='vertical')

OR

plt.xlabel('M0',size=15)
plt.ylabel('label for y axisCF(E-14)',size=15,va='center', rotation='vertical')
plt.text(0.04, 0.5, 'common Y', va='center', rotation='vertical')

Both the codes give the same output.

BRMBU
  • 31
  • 1
  • 10

1 Answers1

0

Firstly, you should use plt.ylabel instead of plt.set_ylabel. In this way, you will fix the reported error.

To align the y label you should use something like

fig.text(0.04, 0.5, 'common Y', va='center', rotation='vertical')

instead of the classical y label, as explained here.

Alessandro Peca
  • 873
  • 1
  • 15
  • 40
  • I have used the code but the result is the same. I have edited the question. – BRMBU Jul 21 '19 at 07:48
  • I think you should also add some part of your code. Do you use `plt.subplots()` to create the multiple graphs? Have you tried to change `0.04, 0.5` in `fig.text()`? – Alessandro Peca Jul 21 '19 at 07:52