Hi Ryan,

Thanks for your answer. Sorry for not replying sooner. I fell asleep
shortly after sending my question.

What is "the OO way"?

Your 1st solution gives:
AttributeError: 'module' object has no attribute 'ticks'

I modified your 2nd solution to accommodate my wishes and needs:
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
for label in ax2.yaxis.get_ticklabels():
    label.set_horizontalalignment('right')
ax2.tick_params(pad=20)
ax1.plot(list(range(11)))
ax1.set_xlim(0,10)
ax2.set_ylim(0,10)
plt.show()

It seems like an awful hack with that for loop, but it works. I'm not
sure, why the secondary right hand side axis don't have right aligned
labels by default. That would make a lot of sense. It would be great,
if I could set the horizontal alignment without having to use a for
loop. It's just plain ugly. In gnuplot it's as simple as this:
set ytics right

Thanks for your help and providing me with a solution.

Tommy

On Sat, Feb 14, 2015 at 1:31 AM, Ryan Nelson <rnelsonc...@gmail.com> wrote:
> Tommy,
>
> You are probably looking for pyplot.xticks. For example, you might want
> something along these lines:
>
> import matplotlib.pyplot as plt
> plt.plot([1,3,2])
> # We'll do this to get the autogenerated positions
> ticks, labels = plt.xticks()
> plt.ticks(ticks, horizontalalignment='left')
> plt.show()
>
> Or if your using the OO way:
>
> import matplotlib.pyplot as plt
> fig = plt.figure()
> ax = fig.add_subplot(111)
> ax.plot([1,3,2])
> labels = ax.get_xticklabels()
> [l.set_horizontalalignment('left') for l in labels]
> plt.show()
>
> I think that's the best way. Hope it helps.
>
> Ryan
>
>
>
> On Fri, Feb 13, 2015 at 7:29 PM, Tommy Carstensen
> <tommy.carsten...@gmail.com> wrote:
>>
>> How can I set the horizontal alignment of a secondary y-axis to
>> 'right'? Currently the numbers are glued to the axis. I want the axis
>> values to be right aligned integers. Thanks.
>>
>>
>> ------------------------------------------------------------------------------
>> Dive into the World of Parallel Programming. The Go Parallel Website,
>> sponsored by Intel and developed in partnership with Slashdot Media, is
>> your
>> hub for all things parallel software development, from weekly thought
>> leadership blogs to news, videos, case studies, tutorials and more. Take a
>> look and join the conversation now. http://goparallel.sourceforge.net/
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotlib-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to