Left-aligned and centered title

Dear users,

I would like label my subplots with a horizontally left-aligned

letter (wanted by the journal) and the normal, centered axes title,
which should both be vertically in line. The following example does
not work:

from matplotlib import pyplot as plt

  import numpy as np



  fig, ax1 = plt.subplots()

  x = np.linspace(1,10)

  y = (sin(x))

  ax1.plot(x,y)



  def subplot_label(ax, letter, title):

  ��� title = ax.set_title(title)

  ��� pos = title.get_position()

  ��� va = title.get_va()

  ��� ax.text(0, pos[1], letter, transform=ax.transAxes,

verticalalignment=va)

  �

  subplot_label(ax1, 'a)', 'This text is not aligned with the

label’)

Which property of the axes title am I missing?

Thank you for your help

Florian,

I think that you need to add the ax.titleOffsetTrans to the ax.transAxes transformation.

ax.text(0,pos[1],letter,transform=ax.transAxes+ax.titleOffsetTrans,va=va)

-Sterling

···

On Mar 17, 2014, at 6:31AM, Florian M. Wagner wrote:

Dear users,

I would like label my subplots with a horizontally left-aligned letter (wanted by the journal) and the normal, centered axes title, which should both be vertically in line. The following example does not work:

from matplotlib import pyplot as plt
import numpy as np

fig, ax1 = plt.subplots()
x = np.linspace(1,10)
y = (sin(x))
ax1.plot(x,y)

def subplot_label(ax, letter, title):
    title = ax.set_title(title)
    pos = title.get_position()
    va = title.get_va()
    ax.text(0, pos[1], letter, transform=ax.transAxes, verticalalignment=va)

subplot_label(ax1, 'a)', 'This text is not aligned with the label')

Which property of the axes title am I missing?

Thank you for your help
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Dear users,

I would like label my subplots with a horizontally left-aligned letter
(wanted by the journal) and the normal, centered axes title, which
should both be vertically in line. The following example does not work:

    from matplotlib import pyplot as plt
    import numpy as np

    fig, ax1 = plt.subplots()
    x = np.linspace(1,10)
    y = (sin(x))
    ax1.plot(x,y)

    def subplot_label(ax, letter, title):
         title = ax.set_title(title)
         pos = title.get_position()
         va = title.get_va()
         ax.text(0, pos[1], letter, transform=ax.transAxes,
    verticalalignment=va)

    subplot_label(ax1, 'a)', 'This text is not aligned with the label')

Which property of the axes title am I missing?

Is the following what you need?

http://matplotlib.org/examples/pylab_examples/titles_demo.html

Eric

···

On 2014/03/17 3:31 AM, Florian M. Wagner wrote:

Thank you for your help

Thank you both a lot,

no idea why I've overseen this.

···

Am 17.03.2014 20:13, schrieb Eric Firing:

On 2014/03/17 3:31 AM, Florian M. Wagner wrote:

Dear users,

I would like label my subplots with a horizontally left-aligned letter
(wanted by the journal) and the normal, centered axes title, which
should both be vertically in line. The following example does not work:

     from matplotlib import pyplot as plt
     import numpy as np

     fig, ax1 = plt.subplots()
     x = np.linspace(1,10)
     y = (sin(x))
     ax1.plot(x,y)

     def subplot_label(ax, letter, title):
          title = ax.set_title(title)
          pos = title.get_position()
          va = title.get_va()
          ax.text(0, pos[1], letter, transform=ax.transAxes,
     verticalalignment=va)

     subplot_label(ax1, 'a)', 'This text is not aligned with the label')

Which property of the axes title am I missing?

Is the following what you need?

http://matplotlib.org/examples/pylab_examples/titles_demo.html

Eric

Thank you for your help

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options