SourceForge logo
SourceForge logo
Menu

matplotlib-users — Discussion related to using matplotlib

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
(3)
Jun
Jul
Aug
(12)
Sep
(12)
Oct
(56)
Nov
(65)
Dec
(37)
2004 Jan
(59)
Feb
(78)
Mar
(153)
Apr
(205)
May
(184)
Jun
(123)
Jul
(171)
Aug
(156)
Sep
(190)
Oct
(120)
Nov
(154)
Dec
(223)
2005 Jan
(184)
Feb
(267)
Mar
(214)
Apr
(286)
May
(320)
Jun
(299)
Jul
(348)
Aug
(283)
Sep
(355)
Oct
(293)
Nov
(232)
Dec
(203)
2006 Jan
(352)
Feb
(358)
Mar
(403)
Apr
(313)
May
(165)
Jun
(281)
Jul
(316)
Aug
(228)
Sep
(279)
Oct
(243)
Nov
(315)
Dec
(345)
2007 Jan
(260)
Feb
(323)
Mar
(340)
Apr
(319)
May
(290)
Jun
(296)
Jul
(221)
Aug
(292)
Sep
(242)
Oct
(248)
Nov
(242)
Dec
(332)
2008 Jan
(312)
Feb
(359)
Mar
(454)
Apr
(287)
May
(340)
Jun
(450)
Jul
(403)
Aug
(324)
Sep
(349)
Oct
(385)
Nov
(363)
Dec
(437)
2009 Jan
(500)
Feb
(301)
Mar
(409)
Apr
(486)
May
(545)
Jun
(391)
Jul
(518)
Aug
(497)
Sep
(492)
Oct
(429)
Nov
(357)
Dec
(310)
2010 Jan
(371)
Feb
(657)
Mar
(519)
Apr
(432)
May
(312)
Jun
(416)
Jul
(477)
Aug
(386)
Sep
(419)
Oct
(435)
Nov
(320)
Dec
(202)
2011 Jan
(321)
Feb
(413)
Mar
(299)
Apr
(215)
May
(284)
Jun
(203)
Jul
(207)
Aug
(314)
Sep
(321)
Oct
(259)
Nov
(347)
Dec
(209)
2012 Jan
(322)
Feb
(414)
Mar
(377)
Apr
(179)
May
(173)
Jun
(234)
Jul
(295)
Aug
(239)
Sep
(276)
Oct
(355)
Nov
(144)
Dec
(108)
2013 Jan
(170)
Feb
(89)
Mar
(204)
Apr
(133)
May
(142)
Jun
(89)
Jul
(160)
Aug
(180)
Sep
(69)
Oct
(136)
Nov
(83)
Dec
(32)
2014 Jan
(71)
Feb
(90)
Mar
(161)
Apr
(117)
May
(78)
Jun
(94)
Jul
(60)
Aug
(83)
Sep
(102)
Oct
(132)
Nov
(154)
Dec
(96)
2015 Jan
(45)
Feb
(138)
Mar
(176)
Apr
(132)
May
(119)
Jun
(124)
Jul
(77)
Aug
(31)
Sep
(34)
Oct
(22)
Nov
(23)
Dec
(9)
2016 Jan
(26)
Feb
(17)
Mar
(10)
Apr
(8)
May
(4)
Jun
(8)
Jul
(6)
Aug
(5)
Sep
(9)
Oct
(4)
Nov
Dec
2017 Jan
(5)
Feb
(7)
Mar
(1)
Apr
(5)
May
Jun
(3)
Jul
(6)
Aug
(1)
Sep
Oct
(2)
Nov
(1)
Dec
2018 Jan
Feb
Mar
Apr
(1)
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2020 Jan
Feb
Mar
Apr
May
(1)
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2025 Jan
(1)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
S M T W T F S
1
2
(6)
3
4
(7)
5
(6)
6
(1)
7
(11)
8
(2)
9
(9)
10
(1)
11
12
(11)
13
(6)
14
(25)
15
16
(6)
17
(6)
18
(13)
19
(13)
20
(5)
21
22
(9)
23
(1)
24
25
26
27
28

Showing 25 results of 25

From: Tommy C. <tom...@gm...> - 2015年02月14日 20:20:36
Again I did this padding manually by introducing yet another magic
constant. Thank you to you and Erik for your help. After using a lot
of hacks and magic constants here are the final plots:
http://www.tommycarstensen.com/matplotlib1.png
http://www.tommycarstensen.com/matplotlib2.png
Notice 1) the right aligned secondary y-axis labels, 2) the
non-overlapping ticks, 3) the padded secondary y-axis labels. I'm
satisfied with this plot / not willing to spend any more time on it.
Thank you for your help.
On Sat, Feb 14, 2015 at 7:54 PM, Tommy Carstensen
<tom...@gm...> wrote:
> Ryan, do you know, if there is any way I can make the padding
> dependent on the tick label sizes?
> for label in ax2.yaxis.get_ticklabels():
> label.set_horizontalalignment('right')
> ax2.tick_params(pad=20)
>
> When the numbers are large, then they are glued to the secondary
> y-axis. When they are small, then they are hovering far away from it.
>
> On Sat, Feb 14, 2015 at 7:20 PM, Ryan Nelson <rne...@gm...> wrote:
>> You're welcome, Tommy. I used gnuplot many years ago, but I've been much
>> happier now that I know MPL.
>>
>> A gnuplot->MPL Rosetta Stone might be a useful blog post for someone. I
>> haven't used gnuplot in so long that I don't think I could do this myself.
>>
>> R
>>
>> On Sat, Feb 14, 2015 at 12:28 PM, Tommy Carstensen
>> <tom...@gm...> wrote:
>>>
>>> Whoa, thanks for a great answer Ryan. I can see, why the level of
>>> control MPL gives you is a great sales pitch. It's one of the reasons,
>>> why I switched from gnuplot after using it for many years and making
>>> many cool plots. The MPL learning curve has just been a bit steep,
>>> when you are used to plot whatever you want.
>>>
>>> On Sat, Feb 14, 2015 at 5:06 PM, Ryan Nelson <rne...@gm...>
>>> wrote:
>>> > Tommy,
>>> >
>>> > I'll try to answer your points in order:
>>> >
>>> > 1) Oops. That should have been "xticks".
>>> > import matplotlib.pyplot as plt
>>> > plt.plot([1,3,2])
>>> > ticks, labels = plt.xticks()
>>> > plt.xticks(ticks, horizontalalignment='left')
>>> > plt.show()
>>> >
>>> >
>>> > 2) Sorry for the ambiguity. "OO" is short for object-oriented. There are
>>> > two
>>> > different approaches that people tend to use to make plots (although
>>> > they
>>> > can be mixed): 1) the "pyplot" way, which uses the pyplot wrapper
>>> > functions
>>> > and 2) the object-oriented way, which modifies the objects directly.
>>> > This is
>>> > what you did in your example where you snag the axes objects and operate
>>> > on
>>> > them directly. The "OO" way is ultimately more powerful, because the
>>> > pyplot
>>> > wrapper functions override some of your control. For example, because
>>> > you
>>> > want twin axes, you might not be able to use the pyplot.xticks function
>>> > (Others, correct me if I'm wrong.), and you lose some fine control. See
>>> > next
>>> > example.
>>> >
>>> > 3) I know it *seems* like the for loop is an "ugly hack". However, you
>>> > have
>>> > to realize that this ultimately gives you a TON of control. Let's say,
>>> > for
>>> > example, that you wanted only one of the labels to be large and red to
>>> > highlight a certain value. Using a modified version of your example, we
>>> > get
>>> > this:
>>> > ______________
>>> > import matplotlib.pyplot as plt
>>> > fig = plt.figure()
>>> > ax1 = fig.add_subplot(111)
>>> > ax2 = ax1.twinx()
>>> > labels = ax2.yaxis.get_ticklabels()
>>> > [l.set_horizontalalignment('right') for l in labels]
>>> > labels[2].set_color('red')
>>> > labels[2].set_fontsize(20)
>>> > ax2.tick_params(pad=20)
>>> > ax1.plot(list(range(11)))
>>> > ax1.set_xlim(0,10)
>>> > ax2.set_ylim(0,10)
>>> > plt.show()
>>> > ____________
>>> > I personally think that this level of control is very, very cool and one
>>> > of
>>> > the big selling points for MPL in general.
>>> >
>>> > Okay. If you want to set the alignment all the time, there might be a
>>> > way to
>>> > control this with matplotlibrc or style sheets:
>>> > http://matplotlib.org/users/customizing.html
>>> > http://matplotlib.org/users/style_sheets.html
>>> > However, I'm not the biggest fan of changing matplotlibrc. Mostly
>>> > because if
>>> > others try to reproduce your plots, they also need your rc file as well.
>>> > I
>>> > haven't used style sheets yet, but that might be a fix to this issue
>>> > (for me
>>> > at least).
>>> >
>>> > Hope that helps.
>>> >
>>> > Ryan
>>> >
>>> > On Sat, Feb 14, 2015 at 10:30 AM, Tommy Carstensen
>>> > <tom...@gm...> wrote:
>>> >>
>>> >> 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 <rne...@gm...>
>>> >> 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
>>> >> > <tom...@gm...> 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
>>> >> >> Mat...@li...
>>> >> >> 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
>>> >> Mat...@li...
>>> >> 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
>>> Mat...@li...
>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
From: Ryan N. <rne...@gm...> - 2015年02月14日 20:17:36
Tommy,
It would be helpful if you included a more complete example that
illustrates the problem. If you are setting the text size yourself,
couldn't you adjust the padding as such "pad=20/txt_size". Then the padding
will be inversely proportional to the size of the text.
I suspect this is related to the text-rendering size issue that I mentioned
in the other thread. I think you could do something like the following to
get the extent of the label:
http://stackoverflow.com/a/8078114/2662077
Then you could adjust the padding very precisely.
There might be an easier solution for your problem, but without an example,
it is hard to say.
Ryan
On Sat, Feb 14, 2015 at 2:54 PM, Tommy Carstensen <
tom...@gm...> wrote:
> Ryan, do you know, if there is any way I can make the padding
> dependent on the tick label sizes?
> for label in ax2.yaxis.get_ticklabels():
> label.set_horizontalalignment('right')
> ax2.tick_params(pad=20)
>
> When the numbers are large, then they are glued to the secondary
> y-axis. When they are small, then they are hovering far away from it.
>
> On Sat, Feb 14, 2015 at 7:20 PM, Ryan Nelson <rne...@gm...>
> wrote:
> > You're welcome, Tommy. I used gnuplot many years ago, but I've been much
> > happier now that I know MPL.
> >
> > A gnuplot->MPL Rosetta Stone might be a useful blog post for someone. I
> > haven't used gnuplot in so long that I don't think I could do this
> myself.
> >
> > R
> >
> > On Sat, Feb 14, 2015 at 12:28 PM, Tommy Carstensen
> > <tom...@gm...> wrote:
> >>
> >> Whoa, thanks for a great answer Ryan. I can see, why the level of
> >> control MPL gives you is a great sales pitch. It's one of the reasons,
> >> why I switched from gnuplot after using it for many years and making
> >> many cool plots. The MPL learning curve has just been a bit steep,
> >> when you are used to plot whatever you want.
> >>
> >> On Sat, Feb 14, 2015 at 5:06 PM, Ryan Nelson <rne...@gm...>
> >> wrote:
> >> > Tommy,
> >> >
> >> > I'll try to answer your points in order:
> >> >
> >> > 1) Oops. That should have been "xticks".
> >> > import matplotlib.pyplot as plt
> >> > plt.plot([1,3,2])
> >> > ticks, labels = plt.xticks()
> >> > plt.xticks(ticks, horizontalalignment='left')
> >> > plt.show()
> >> >
> >> >
> >> > 2) Sorry for the ambiguity. "OO" is short for object-oriented. There
> are
> >> > two
> >> > different approaches that people tend to use to make plots (although
> >> > they
> >> > can be mixed): 1) the "pyplot" way, which uses the pyplot wrapper
> >> > functions
> >> > and 2) the object-oriented way, which modifies the objects directly.
> >> > This is
> >> > what you did in your example where you snag the axes objects and
> operate
> >> > on
> >> > them directly. The "OO" way is ultimately more powerful, because the
> >> > pyplot
> >> > wrapper functions override some of your control. For example, because
> >> > you
> >> > want twin axes, you might not be able to use the pyplot.xticks
> function
> >> > (Others, correct me if I'm wrong.), and you lose some fine control.
> See
> >> > next
> >> > example.
> >> >
> >> > 3) I know it *seems* like the for loop is an "ugly hack". However, you
> >> > have
> >> > to realize that this ultimately gives you a TON of control. Let's say,
> >> > for
> >> > example, that you wanted only one of the labels to be large and red to
> >> > highlight a certain value. Using a modified version of your example,
> we
> >> > get
> >> > this:
> >> > ______________
> >> > import matplotlib.pyplot as plt
> >> > fig = plt.figure()
> >> > ax1 = fig.add_subplot(111)
> >> > ax2 = ax1.twinx()
> >> > labels = ax2.yaxis.get_ticklabels()
> >> > [l.set_horizontalalignment('right') for l in labels]
> >> > labels[2].set_color('red')
> >> > labels[2].set_fontsize(20)
> >> > ax2.tick_params(pad=20)
> >> > ax1.plot(list(range(11)))
> >> > ax1.set_xlim(0,10)
> >> > ax2.set_ylim(0,10)
> >> > plt.show()
> >> > ____________
> >> > I personally think that this level of control is very, very cool and
> one
> >> > of
> >> > the big selling points for MPL in general.
> >> >
> >> > Okay. If you want to set the alignment all the time, there might be a
> >> > way to
> >> > control this with matplotlibrc or style sheets:
> >> > http://matplotlib.org/users/customizing.html
> >> > http://matplotlib.org/users/style_sheets.html
> >> > However, I'm not the biggest fan of changing matplotlibrc. Mostly
> >> > because if
> >> > others try to reproduce your plots, they also need your rc file as
> well.
> >> > I
> >> > haven't used style sheets yet, but that might be a fix to this issue
> >> > (for me
> >> > at least).
> >> >
> >> > Hope that helps.
> >> >
> >> > Ryan
> >> >
> >> > On Sat, Feb 14, 2015 at 10:30 AM, Tommy Carstensen
> >> > <tom...@gm...> wrote:
> >> >>
> >> >> 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 <rne...@gm...>
> >> >> 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
> >> >> > <tom...@gm...> 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
> >> >> >> Mat...@li...
> >> >> >> 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
> >> >> Mat...@li...
> >> >> 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
> >> Mat...@li...
> >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
> >
>
From: Tommy C. <tom...@gm...> - 2015年02月14日 19:55:25
Ryan, do you know, if there is any way I can make the padding
dependent on the tick label sizes?
for label in ax2.yaxis.get_ticklabels():
 label.set_horizontalalignment('right')
ax2.tick_params(pad=20)
When the numbers are large, then they are glued to the secondary
y-axis. When they are small, then they are hovering far away from it.
On Sat, Feb 14, 2015 at 7:20 PM, Ryan Nelson <rne...@gm...> wrote:
> You're welcome, Tommy. I used gnuplot many years ago, but I've been much
> happier now that I know MPL.
>
> A gnuplot->MPL Rosetta Stone might be a useful blog post for someone. I
> haven't used gnuplot in so long that I don't think I could do this myself.
>
> R
>
> On Sat, Feb 14, 2015 at 12:28 PM, Tommy Carstensen
> <tom...@gm...> wrote:
>>
>> Whoa, thanks for a great answer Ryan. I can see, why the level of
>> control MPL gives you is a great sales pitch. It's one of the reasons,
>> why I switched from gnuplot after using it for many years and making
>> many cool plots. The MPL learning curve has just been a bit steep,
>> when you are used to plot whatever you want.
>>
>> On Sat, Feb 14, 2015 at 5:06 PM, Ryan Nelson <rne...@gm...>
>> wrote:
>> > Tommy,
>> >
>> > I'll try to answer your points in order:
>> >
>> > 1) Oops. That should have been "xticks".
>> > import matplotlib.pyplot as plt
>> > plt.plot([1,3,2])
>> > ticks, labels = plt.xticks()
>> > plt.xticks(ticks, horizontalalignment='left')
>> > plt.show()
>> >
>> >
>> > 2) Sorry for the ambiguity. "OO" is short for object-oriented. There are
>> > two
>> > different approaches that people tend to use to make plots (although
>> > they
>> > can be mixed): 1) the "pyplot" way, which uses the pyplot wrapper
>> > functions
>> > and 2) the object-oriented way, which modifies the objects directly.
>> > This is
>> > what you did in your example where you snag the axes objects and operate
>> > on
>> > them directly. The "OO" way is ultimately more powerful, because the
>> > pyplot
>> > wrapper functions override some of your control. For example, because
>> > you
>> > want twin axes, you might not be able to use the pyplot.xticks function
>> > (Others, correct me if I'm wrong.), and you lose some fine control. See
>> > next
>> > example.
>> >
>> > 3) I know it *seems* like the for loop is an "ugly hack". However, you
>> > have
>> > to realize that this ultimately gives you a TON of control. Let's say,
>> > for
>> > example, that you wanted only one of the labels to be large and red to
>> > highlight a certain value. Using a modified version of your example, we
>> > get
>> > this:
>> > ______________
>> > import matplotlib.pyplot as plt
>> > fig = plt.figure()
>> > ax1 = fig.add_subplot(111)
>> > ax2 = ax1.twinx()
>> > labels = ax2.yaxis.get_ticklabels()
>> > [l.set_horizontalalignment('right') for l in labels]
>> > labels[2].set_color('red')
>> > labels[2].set_fontsize(20)
>> > ax2.tick_params(pad=20)
>> > ax1.plot(list(range(11)))
>> > ax1.set_xlim(0,10)
>> > ax2.set_ylim(0,10)
>> > plt.show()
>> > ____________
>> > I personally think that this level of control is very, very cool and one
>> > of
>> > the big selling points for MPL in general.
>> >
>> > Okay. If you want to set the alignment all the time, there might be a
>> > way to
>> > control this with matplotlibrc or style sheets:
>> > http://matplotlib.org/users/customizing.html
>> > http://matplotlib.org/users/style_sheets.html
>> > However, I'm not the biggest fan of changing matplotlibrc. Mostly
>> > because if
>> > others try to reproduce your plots, they also need your rc file as well.
>> > I
>> > haven't used style sheets yet, but that might be a fix to this issue
>> > (for me
>> > at least).
>> >
>> > Hope that helps.
>> >
>> > Ryan
>> >
>> > On Sat, Feb 14, 2015 at 10:30 AM, Tommy Carstensen
>> > <tom...@gm...> wrote:
>> >>
>> >> 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 <rne...@gm...>
>> >> 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
>> >> > <tom...@gm...> 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
>> >> >> Mat...@li...
>> >> >> 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
>> >> Mat...@li...
>> >> 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
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
From: Tommy C. <tom...@gm...> - 2015年02月14日 19:48:26
Ryan, I stopped using gnuplot, because it requires the data to be
formatted in very specific ways :) I remember having functions just to
format the input data correctly for heat plots and the wrapper scripts
I wrote were quite convoluted. Matplotlib has its advantages for sure.
Otherwise I would not have switched. I'm just frustrated with being
back at the start line. Thanks for your help and bearing with my
impatience.
On Sat, Feb 14, 2015 at 7:42 PM, Ryan Nelson <rne...@gm...> wrote:
> Yep. I see your problem. My function and Eric's object should help here.
>
> A sore-spot with many folks coming over to Matplotlib from "X" is the fact
> that MPL does not calculate the size of text until the plot is generated.
> That means it doesn't always get text positioning, etc. exactly correct.
> That takes a little getting used to, and for me, it is minor.
>
> Admit it, Gnuplot as it's quirks as well :) I always hated that it wouldn't
> cut off some markers at the edge of the screen. For example, with Gnuplot
> 4.6rev5 the following
> plot x with points ps 7
> Leads to a bunch of markers running over the axes limits. (Maybe there is a
> way to fix this now. Many years ago that was not the case.)
>
> Ryan
>
> On Sat, Feb 14, 2015 at 2:18 PM, Tommy Carstensen
> <tom...@gm...> wrote:
>>
>> Ryan, my use case is indeed that I want to avoid overlapping ticks and
>> I want to avoid them by not displaying them. Here is a guy with the
>> same problem:
>>
>> http://stackoverflow.com/questions/9422587/overlapping-y-axis-tick-label-and-x-axis-tick-label-in-matplotlib
>>
>> Here is the problem at the top left of my plot:
>> www.tommycarstensen.com/matplotlib.png
>>
>> I'll just set the ticks manually. Sadly seems like the easiest thing to
>> do.
>>
>> On Sat, Feb 14, 2015 at 7:01 PM, Ryan Nelson <rne...@gm...>
>> wrote:
>> > Tommy,
>> >
>> > I'm sorry. I forgot to hit send all *again*. Below is my original
>> > message,
>> > but the function I wrote is updated because it wasn't exactly
>> > correct....
>> >
>> > Ah. I was working on something to help out, so I'm just seeing Eric's
>> > very
>> > elegant solution, which I have yet to try. However, I feel like you
>> > might
>> > run into some problems if you always drop the first tick. For example,
>> > try
>> > this plot:
>> > ______________
>> > import matplotlib.pyplot as plt
>> > from matplotlib.ticker import MultipleLocator
>> > import numpy as np
>> > xs = np.linspace(2,12,1000)
>> > ys = np.sin(xs)
>> > n = 5
>> > fig = plt.figure()
>> > ax1 = fig.add_subplot(111)
>> > ax1.plot(xs, ys)
>> > ax1.xaxis.set_major_locator(MultipleLocator(5))
>> > plt.show()
>> > _____________
>> > In this case, dropping the first tick will result in only one tick on
>> > the
>> > screen.
>> >
>> > What is your use-case? Are you annoyed that the axis labels are
>> > overlapping
>> > at the far left? If that's the case, here's a little function
>> > (trimticks)
>> > that I whipped up that might help. It drops the far left or far right
>> > label
>> > if it is exactly at the edge of the axes. Should work for y axes as
>> > well.
>> > _____________
>> > def trimticks(ax, n=5):
>> > xmin, xmax = ax.get_xlim()
>> > if xmin%n == 0:
>> > xmin = xmin+n
>> > else:
>> > xmin = xmin + n - xmin%n
>> >
>> > if not xmax%n == 0:
>> > xmax = xmax + n - xmax%n
>> >
>> > ticks = np.arange(xmin, xmax, n)
>> > ax.set_xticks(ticks)
>> >
>> > import matplotlib.pyplot as plt
>> > from matplotlib.ticker import MultipleLocator
>> > import numpy as np
>> > xs = np.linspace(0,20,10000)
>> > ys = np.sin(xs)
>> > fig = plt.figure()
>> > ax1 = fig.add_subplot(111)
>> > ax1.plot(xs, ys)
>> > trimticks(ax1)
>> > plt.show()
>> >
>> > ___________________
>> >
>> >
>> > On Sat, Feb 14, 2015 at 1:45 PM, Tommy Carstensen
>> > <tom...@gm...> wrote:
>> >>
>> >> Erik, that doesn't seem to work either. I tried this:
>> >>
>> >> import matplotlib.pyplot as plt
>> >> from matplotlib.ticker import MultipleLocator
>> >> class TrimmedMultipleLocator(MultipleLocator):
>> >> def tick_values(self, vmin, vmax):
>> >> return MultipleLocator.tick_values(self, vmin, vmax)[2:]
>> >> fig = plt.figure()
>> >> ax1 = fig.add_subplot(111)
>> >> ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5))
>> >> #xticks[0].label1.set_visible(False)
>> >> #xticks[-1].label1.set_visible(False)
>> >> #ax1.set_xticks(ax1.xaxis.get_major_ticks()[1:-1])
>> >> ax1.plot(list(range(21)))
>> >> plt.show()
>> >>
>> >> Here is an example of the use of prune='lower', but it does not allow
>> >> one to set the tick step size:
>> >>
>> >>
>> >> http://stackoverflow.com/questions/9422587/overlapping-y-axis-tick-label-and-x-axis-tick-label-in-matplotlib
>> >>
>> >> I think my best bet is to just set those ticks manually.
>> >>
>> >> On Sat, Feb 14, 2015 at 6:19 PM, Eric Firing <ef...@ha...>
>> >> wrote:
>> >> > On 2015年02月14日 7:33 AM, Tommy Carstensen wrote:
>> >> >> Thanks again Ryan. That's exactly what I want to achieve; i.e.
>> >> >> remove
>> >> >> the tick at 0 and only keep 5 and 10. Your solution works, but it's
>> >> >> a
>> >> >> bit of hack to use magic constants. I could however get those values
>> >> >> from the xlim.
>> >> >>
>> >> >> Eric, I would describe the desired tick placement algorithm as
>> >> >> removing the first tick on the axis. It can be achieved like this:
>> >> >> ax1.xaxis.set_major_locator(MaxNLocator(prune='lower'))
>> >> >
>> >> > Aha! The problem is that the MaxNLocator is the only one with the
>> >> > prune
>> >> > kwarg. It could be added to the MultipleLocator. For now, though,
>> >> > you
>> >> > can make your own specialized Locator, hardwired to omit the first
>> >> > tick,
>> >> > like this:
>> >> >
>> >> > from matplotlib.ticker import MultipleLocator
>> >> >
>> >> > class TrimmedMultipleLocator(MultipleLocator):
>> >> > def tick_values(self, vmin, vmax):
>> >> > return MultipleLocator.tick_values(self, vmin, vmax)[1:]
>> >> >
>> >> > then just use
>> >> >
>> >> > ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5))
>> >> >
>> >> > I haven't tested it--but give it a try. What it is doing is making a
>> >> > subclass of MultipleLocator, and altering only the one little bit of
>> >> > its
>> >> > behavior that you want to modify. Everything else is automatically
>> >> > inherited from the base class, MultipleLocator.
>> >> >
>> >> > Eric
>> >> >
>> >> >
>> >> >>
>> >> >> But that then overrides this:
>> >> >> ax1.xaxis.set_major_locator(MultipleLocator(5))
>> >> >>
>> >> >> On Sat, Feb 14, 2015 at 5:27 PM, Ryan Nelson <rne...@gm...>
>> >> >> wrote:
>> >> >>> Tommy, (Sorry for the doubleup. I just realized I forgot to hit
>> >> >>> reply-all.)
>> >> >>>
>> >> >>> Do you want to remove the tick at 0 and only have 5,10, etc.? Could
>> >> >>> you just
>> >> >>> do something like this instead:
>> >> >>>
>> >> >>> import matplotlib.pyplot as plt
>> >> >>> from matplotlib.ticker import MultipleLocator
>> >> >>> fig = plt.figure()
>> >> >>> ax1 = fig.add_subplot(111)
>> >> >>> ax1.set_xticks(range(5,11,5))
>> >> >>> ax1.plot(range(11))
>> >> >>> plt.show()
>> >> >>>
>> >> >>> Ryan
>> >> >>>
>> >> >>>
>> >> >>> On Sat, Feb 14, 2015 at 10:47 AM, Tommy Carstensen
>> >> >>> <tom...@gm...> wrote:
>> >> >>>>
>> >> >>>> Thanks for you answer Eric. I had to get some sleep before trying
>> >> >>>> out
>> >> >>>> things. I currently have the code below, but it does not remove
>> >> >>>> the
>> >> >>>> zero value tick. It removes the tick at 5 and 10 however.
>> >> >>>>
>> >> >>>> import matplotlib.pyplot as plt
>> >> >>>> from matplotlib.ticker import MultipleLocator
>> >> >>>> fig = plt.figure()
>> >> >>>> ax1 = fig.add_subplot(111)
>> >> >>>> ax1.xaxis.set_major_locator(MultipleLocator(5))
>> >> >>>> xticks = ax1.xaxis.get_major_ticks()
>> >> >>>> #xticks[0].label1.set_visible(False)
>> >> >>>> #xticks[-1].label1.set_visible(False)
>> >> >>>> ax1.set_xticks(ax1.get_xticks()[1:-1])
>> >> >>>> ax1.plot(list(range(11)))
>> >> >>>> plt.show()
>> >> >>>>
>> >> >>>> On Sat, Feb 14, 2015 at 2:01 AM, Eric Firing <ef...@ha...>
>> >> >>>> wrote:
>> >> >>>>> On 2015年02月13日 3:29 PM, Tommy Carstensen wrote:
>> >> >>>>>> Is it possible to combine MultipleLocator and MaxNLocator? One
>> >> >>>>>> seems
>> >> >>>>>> to erase the effect of the other.
>> >> >>>>>
>> >> >>>>> They are for different situations. MultipleLocator is for when
>> >> >>>>> you
>> >> >>>>> know
>> >> >>>>> what you want your tick interval to be; MaxNLocator is for when
>> >> >>>>> you
>> >> >>>>> don't know that, but you do know roughly how many ticks you want,
>> >> >>>>> and
>> >> >>>>> what sort of numerical intervals are acceptable.
>> >> >>>>>
>> >> >>>>> Eric
>> >> >>>>>
>> >> >>>>>
>> >> >>>>>
>> >> >>>>>
>> >> >>>>>
>> >> >>>>> ------------------------------------------------------------------------------
>> >> >>>>> 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
>> >> >>>>> Mat...@li...
>> >> >>>>> 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
>> >> >>>> Mat...@li...
>> >> >>>> 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
>> >> >> Mat...@li...
>> >> >> 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
>> >> > Mat...@li...
>> >> > 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
>> >> Mat...@li...
>> >> 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
>> > Mat...@li...
>> > 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Ryan N. <rne...@gm...> - 2015年02月14日 19:42:36
Yep. I see your problem. My function and Eric's object should help here.
A sore-spot with many folks coming over to Matplotlib from "X" is the fact
that MPL does not calculate the size of text until the plot is generated.
That means it doesn't always get text positioning, etc. exactly correct.
That takes a little getting used to, and for me, it is minor.
Admit it, Gnuplot as it's quirks as well :) I always hated that it
wouldn't cut off some markers at the edge of the screen. For example, with
Gnuplot 4.6rev5 the following
plot x with points ps 7
Leads to a bunch of markers running over the axes limits. (Maybe there is a
way to fix this now. Many years ago that was not the case.)
Ryan
On Sat, Feb 14, 2015 at 2:18 PM, Tommy Carstensen <
tom...@gm...> wrote:
> Ryan, my use case is indeed that I want to avoid overlapping ticks and
> I want to avoid them by not displaying them. Here is a guy with the
> same problem:
>
> http://stackoverflow.com/questions/9422587/overlapping-y-axis-tick-label-and-x-axis-tick-label-in-matplotlib
>
> Here is the problem at the top left of my plot:
> www.tommycarstensen.com/matplotlib.png
>
> I'll just set the ticks manually. Sadly seems like the easiest thing to do.
>
> On Sat, Feb 14, 2015 at 7:01 PM, Ryan Nelson <rne...@gm...>
> wrote:
> > Tommy,
> >
> > I'm sorry. I forgot to hit send all *again*. Below is my original
> message,
> > but the function I wrote is updated because it wasn't exactly correct....
> >
> > Ah. I was working on something to help out, so I'm just seeing Eric's
> very
> > elegant solution, which I have yet to try. However, I feel like you might
> > run into some problems if you always drop the first tick. For example,
> try
> > this plot:
> > ______________
> > import matplotlib.pyplot as plt
> > from matplotlib.ticker import MultipleLocator
> > import numpy as np
> > xs = np.linspace(2,12,1000)
> > ys = np.sin(xs)
> > n = 5
> > fig = plt.figure()
> > ax1 = fig.add_subplot(111)
> > ax1.plot(xs, ys)
> > ax1.xaxis.set_major_locator(MultipleLocator(5))
> > plt.show()
> > _____________
> > In this case, dropping the first tick will result in only one tick on the
> > screen.
> >
> > What is your use-case? Are you annoyed that the axis labels are
> overlapping
> > at the far left? If that's the case, here's a little function (trimticks)
> > that I whipped up that might help. It drops the far left or far right
> label
> > if it is exactly at the edge of the axes. Should work for y axes as well.
> > _____________
> > def trimticks(ax, n=5):
> > xmin, xmax = ax.get_xlim()
> > if xmin%n == 0:
> > xmin = xmin+n
> > else:
> > xmin = xmin + n - xmin%n
> >
> > if not xmax%n == 0:
> > xmax = xmax + n - xmax%n
> >
> > ticks = np.arange(xmin, xmax, n)
> > ax.set_xticks(ticks)
> >
> > import matplotlib.pyplot as plt
> > from matplotlib.ticker import MultipleLocator
> > import numpy as np
> > xs = np.linspace(0,20,10000)
> > ys = np.sin(xs)
> > fig = plt.figure()
> > ax1 = fig.add_subplot(111)
> > ax1.plot(xs, ys)
> > trimticks(ax1)
> > plt.show()
> >
> > ___________________
> >
> >
> > On Sat, Feb 14, 2015 at 1:45 PM, Tommy Carstensen
> > <tom...@gm...> wrote:
> >>
> >> Erik, that doesn't seem to work either. I tried this:
> >>
> >> import matplotlib.pyplot as plt
> >> from matplotlib.ticker import MultipleLocator
> >> class TrimmedMultipleLocator(MultipleLocator):
> >> def tick_values(self, vmin, vmax):
> >> return MultipleLocator.tick_values(self, vmin, vmax)[2:]
> >> fig = plt.figure()
> >> ax1 = fig.add_subplot(111)
> >> ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5))
> >> #xticks[0].label1.set_visible(False)
> >> #xticks[-1].label1.set_visible(False)
> >> #ax1.set_xticks(ax1.xaxis.get_major_ticks()[1:-1])
> >> ax1.plot(list(range(21)))
> >> plt.show()
> >>
> >> Here is an example of the use of prune='lower', but it does not allow
> >> one to set the tick step size:
> >>
> >>
> http://stackoverflow.com/questions/9422587/overlapping-y-axis-tick-label-and-x-axis-tick-label-in-matplotlib
> >>
> >> I think my best bet is to just set those ticks manually.
> >>
> >> On Sat, Feb 14, 2015 at 6:19 PM, Eric Firing <ef...@ha...>
> wrote:
> >> > On 2015年02月14日 7:33 AM, Tommy Carstensen wrote:
> >> >> Thanks again Ryan. That's exactly what I want to achieve; i.e. remove
> >> >> the tick at 0 and only keep 5 and 10. Your solution works, but it's a
> >> >> bit of hack to use magic constants. I could however get those values
> >> >> from the xlim.
> >> >>
> >> >> Eric, I would describe the desired tick placement algorithm as
> >> >> removing the first tick on the axis. It can be achieved like this:
> >> >> ax1.xaxis.set_major_locator(MaxNLocator(prune='lower'))
> >> >
> >> > Aha! The problem is that the MaxNLocator is the only one with the
> prune
> >> > kwarg. It could be added to the MultipleLocator. For now, though,
> you
> >> > can make your own specialized Locator, hardwired to omit the first
> tick,
> >> > like this:
> >> >
> >> > from matplotlib.ticker import MultipleLocator
> >> >
> >> > class TrimmedMultipleLocator(MultipleLocator):
> >> > def tick_values(self, vmin, vmax):
> >> > return MultipleLocator.tick_values(self, vmin, vmax)[1:]
> >> >
> >> > then just use
> >> >
> >> > ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5))
> >> >
> >> > I haven't tested it--but give it a try. What it is doing is making a
> >> > subclass of MultipleLocator, and altering only the one little bit of
> its
> >> > behavior that you want to modify. Everything else is automatically
> >> > inherited from the base class, MultipleLocator.
> >> >
> >> > Eric
> >> >
> >> >
> >> >>
> >> >> But that then overrides this:
> >> >> ax1.xaxis.set_major_locator(MultipleLocator(5))
> >> >>
> >> >> On Sat, Feb 14, 2015 at 5:27 PM, Ryan Nelson <rne...@gm...>
> >> >> wrote:
> >> >>> Tommy, (Sorry for the doubleup. I just realized I forgot to hit
> >> >>> reply-all.)
> >> >>>
> >> >>> Do you want to remove the tick at 0 and only have 5,10, etc.? Could
> >> >>> you just
> >> >>> do something like this instead:
> >> >>>
> >> >>> import matplotlib.pyplot as plt
> >> >>> from matplotlib.ticker import MultipleLocator
> >> >>> fig = plt.figure()
> >> >>> ax1 = fig.add_subplot(111)
> >> >>> ax1.set_xticks(range(5,11,5))
> >> >>> ax1.plot(range(11))
> >> >>> plt.show()
> >> >>>
> >> >>> Ryan
> >> >>>
> >> >>>
> >> >>> On Sat, Feb 14, 2015 at 10:47 AM, Tommy Carstensen
> >> >>> <tom...@gm...> wrote:
> >> >>>>
> >> >>>> Thanks for you answer Eric. I had to get some sleep before trying
> out
> >> >>>> things. I currently have the code below, but it does not remove the
> >> >>>> zero value tick. It removes the tick at 5 and 10 however.
> >> >>>>
> >> >>>> import matplotlib.pyplot as plt
> >> >>>> from matplotlib.ticker import MultipleLocator
> >> >>>> fig = plt.figure()
> >> >>>> ax1 = fig.add_subplot(111)
> >> >>>> ax1.xaxis.set_major_locator(MultipleLocator(5))
> >> >>>> xticks = ax1.xaxis.get_major_ticks()
> >> >>>> #xticks[0].label1.set_visible(False)
> >> >>>> #xticks[-1].label1.set_visible(False)
> >> >>>> ax1.set_xticks(ax1.get_xticks()[1:-1])
> >> >>>> ax1.plot(list(range(11)))
> >> >>>> plt.show()
> >> >>>>
> >> >>>> On Sat, Feb 14, 2015 at 2:01 AM, Eric Firing <ef...@ha...>
> >> >>>> wrote:
> >> >>>>> On 2015年02月13日 3:29 PM, Tommy Carstensen wrote:
> >> >>>>>> Is it possible to combine MultipleLocator and MaxNLocator? One
> >> >>>>>> seems
> >> >>>>>> to erase the effect of the other.
> >> >>>>>
> >> >>>>> They are for different situations. MultipleLocator is for when
> you
> >> >>>>> know
> >> >>>>> what you want your tick interval to be; MaxNLocator is for when
> you
> >> >>>>> don't know that, but you do know roughly how many ticks you want,
> >> >>>>> and
> >> >>>>> what sort of numerical intervals are acceptable.
> >> >>>>>
> >> >>>>> Eric
> >> >>>>>
> >> >>>>>
> >> >>>>>
> >> >>>>>
> >> >>>>>
> ------------------------------------------------------------------------------
> >> >>>>> 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
> >> >>>>> Mat...@li...
> >> >>>>> 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
> >> >>>> Mat...@li...
> >> >>>> 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
> >> >> Mat...@li...
> >> >> 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
> >> > Mat...@li...
> >> > 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
> >> Mat...@li...
> >> 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
> > Mat...@li...
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
>
From: Tommy C. <tom...@gm...> - 2015年02月14日 19:40:04
Thanks Eric. I decided to get peace of mind and just set the tick
labels manually. I can't afford to spend several hours on all of my
plots. I appreciate your help a lot.
On Sat, Feb 14, 2015 at 7:37 PM, Eric Firing <ef...@ha...> wrote:
> On 2015年02月14日 9:15 AM, Tommy Carstensen wrote:
>>
>> Eric, it works if I do:
>> return MultipleLocator.tick_values(self, vmin, vmax)[2:]
>>
>> But not if I do as first suggested by you:
>> return MultipleLocator.tick_values(self, vmin, vmax)[1:]
>>
>
> Are you using my test script but getting a different result? If not, what
> is the difference in your test script?
>
>> I don't understand this behaviour. It should be [1:]. I'll just set
>> the ticks manually. Seems to be the easiest thing. It would be
>> awesome, if MPL had the same behaviour as gnuplot, which allows me to
>> simply do:
>> set xtics <start>, <incr>
>
>
> def xtics(ax, start, incr):
> stop = ax.dataLim.x1 + 0.01 * incr
> ax.xaxis.set_ticks(np.arange(start, stop, incr))
>
>
> Now invoke that function *after* all your plot calls, so that the dataLim
> bounding box includes all the data in your plot.
>
> Eric
From: Eric F. <ef...@ha...> - 2015年02月14日 19:37:20
On 2015年02月14日 9:15 AM, Tommy Carstensen wrote:
> Eric, it works if I do:
> return MultipleLocator.tick_values(self, vmin, vmax)[2:]
>
> But not if I do as first suggested by you:
> return MultipleLocator.tick_values(self, vmin, vmax)[1:]
>
Are you using my test script but getting a different result? If not, 
what is the difference in your test script?
> I don't understand this behaviour. It should be [1:]. I'll just set
> the ticks manually. Seems to be the easiest thing. It would be
> awesome, if MPL had the same behaviour as gnuplot, which allows me to
> simply do:
> set xtics <start>, <incr>
def xtics(ax, start, incr):
 stop = ax.dataLim.x1 + 0.01 * incr
 ax.xaxis.set_ticks(np.arange(start, stop, incr))
Now invoke that function *after* all your plot calls, so that the 
dataLim bounding box includes all the data in your plot.
Eric
From: Ryan N. <rne...@gm...> - 2015年02月14日 19:20:12
You're welcome, Tommy. I used gnuplot many years ago, but I've been much
happier now that I know MPL.
A gnuplot->MPL Rosetta Stone might be a useful blog post for someone. I
haven't used gnuplot in so long that I don't think I could do this myself.
R
On Sat, Feb 14, 2015 at 12:28 PM, Tommy Carstensen <
tom...@gm...> wrote:
> Whoa, thanks for a great answer Ryan. I can see, why the level of
> control MPL gives you is a great sales pitch. It's one of the reasons,
> why I switched from gnuplot after using it for many years and making
> many cool plots. The MPL learning curve has just been a bit steep,
> when you are used to plot whatever you want.
>
> On Sat, Feb 14, 2015 at 5:06 PM, Ryan Nelson <rne...@gm...>
> wrote:
> > Tommy,
> >
> > I'll try to answer your points in order:
> >
> > 1) Oops. That should have been "xticks".
> > import matplotlib.pyplot as plt
> > plt.plot([1,3,2])
> > ticks, labels = plt.xticks()
> > plt.xticks(ticks, horizontalalignment='left')
> > plt.show()
> >
> >
> > 2) Sorry for the ambiguity. "OO" is short for object-oriented. There are
> two
> > different approaches that people tend to use to make plots (although they
> > can be mixed): 1) the "pyplot" way, which uses the pyplot wrapper
> functions
> > and 2) the object-oriented way, which modifies the objects directly.
> This is
> > what you did in your example where you snag the axes objects and operate
> on
> > them directly. The "OO" way is ultimately more powerful, because the
> pyplot
> > wrapper functions override some of your control. For example, because you
> > want twin axes, you might not be able to use the pyplot.xticks function
> > (Others, correct me if I'm wrong.), and you lose some fine control. See
> next
> > example.
> >
> > 3) I know it *seems* like the for loop is an "ugly hack". However, you
> have
> > to realize that this ultimately gives you a TON of control. Let's say,
> for
> > example, that you wanted only one of the labels to be large and red to
> > highlight a certain value. Using a modified version of your example, we
> get
> > this:
> > ______________
> > import matplotlib.pyplot as plt
> > fig = plt.figure()
> > ax1 = fig.add_subplot(111)
> > ax2 = ax1.twinx()
> > labels = ax2.yaxis.get_ticklabels()
> > [l.set_horizontalalignment('right') for l in labels]
> > labels[2].set_color('red')
> > labels[2].set_fontsize(20)
> > ax2.tick_params(pad=20)
> > ax1.plot(list(range(11)))
> > ax1.set_xlim(0,10)
> > ax2.set_ylim(0,10)
> > plt.show()
> > ____________
> > I personally think that this level of control is very, very cool and one
> of
> > the big selling points for MPL in general.
> >
> > Okay. If you want to set the alignment all the time, there might be a
> way to
> > control this with matplotlibrc or style sheets:
> > http://matplotlib.org/users/customizing.html
> > http://matplotlib.org/users/style_sheets.html
> > However, I'm not the biggest fan of changing matplotlibrc. Mostly
> because if
> > others try to reproduce your plots, they also need your rc file as well.
> I
> > haven't used style sheets yet, but that might be a fix to this issue
> (for me
> > at least).
> >
> > Hope that helps.
> >
> > Ryan
> >
> > On Sat, Feb 14, 2015 at 10:30 AM, Tommy Carstensen
> > <tom...@gm...> wrote:
> >>
> >> 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 <rne...@gm...>
> >> 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
> >> > <tom...@gm...> 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
> >> >> Mat...@li...
> >> >> 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
> >> Mat...@li...
> >> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Tommy C. <tom...@gm...> - 2015年02月14日 19:18:53
Ryan, my use case is indeed that I want to avoid overlapping ticks and
I want to avoid them by not displaying them. Here is a guy with the
same problem:
http://stackoverflow.com/questions/9422587/overlapping-y-axis-tick-label-and-x-axis-tick-label-in-matplotlib
Here is the problem at the top left of my plot:
www.tommycarstensen.com/matplotlib.png
I'll just set the ticks manually. Sadly seems like the easiest thing to do.
On Sat, Feb 14, 2015 at 7:01 PM, Ryan Nelson <rne...@gm...> wrote:
> Tommy,
>
> I'm sorry. I forgot to hit send all *again*. Below is my original message,
> but the function I wrote is updated because it wasn't exactly correct....
>
> Ah. I was working on something to help out, so I'm just seeing Eric's very
> elegant solution, which I have yet to try. However, I feel like you might
> run into some problems if you always drop the first tick. For example, try
> this plot:
> ______________
> import matplotlib.pyplot as plt
> from matplotlib.ticker import MultipleLocator
> import numpy as np
> xs = np.linspace(2,12,1000)
> ys = np.sin(xs)
> n = 5
> fig = plt.figure()
> ax1 = fig.add_subplot(111)
> ax1.plot(xs, ys)
> ax1.xaxis.set_major_locator(MultipleLocator(5))
> plt.show()
> _____________
> In this case, dropping the first tick will result in only one tick on the
> screen.
>
> What is your use-case? Are you annoyed that the axis labels are overlapping
> at the far left? If that's the case, here's a little function (trimticks)
> that I whipped up that might help. It drops the far left or far right label
> if it is exactly at the edge of the axes. Should work for y axes as well.
> _____________
> def trimticks(ax, n=5):
> xmin, xmax = ax.get_xlim()
> if xmin%n == 0:
> xmin = xmin+n
> else:
> xmin = xmin + n - xmin%n
>
> if not xmax%n == 0:
> xmax = xmax + n - xmax%n
>
> ticks = np.arange(xmin, xmax, n)
> ax.set_xticks(ticks)
>
> import matplotlib.pyplot as plt
> from matplotlib.ticker import MultipleLocator
> import numpy as np
> xs = np.linspace(0,20,10000)
> ys = np.sin(xs)
> fig = plt.figure()
> ax1 = fig.add_subplot(111)
> ax1.plot(xs, ys)
> trimticks(ax1)
> plt.show()
>
> ___________________
>
>
> On Sat, Feb 14, 2015 at 1:45 PM, Tommy Carstensen
> <tom...@gm...> wrote:
>>
>> Erik, that doesn't seem to work either. I tried this:
>>
>> import matplotlib.pyplot as plt
>> from matplotlib.ticker import MultipleLocator
>> class TrimmedMultipleLocator(MultipleLocator):
>> def tick_values(self, vmin, vmax):
>> return MultipleLocator.tick_values(self, vmin, vmax)[2:]
>> fig = plt.figure()
>> ax1 = fig.add_subplot(111)
>> ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5))
>> #xticks[0].label1.set_visible(False)
>> #xticks[-1].label1.set_visible(False)
>> #ax1.set_xticks(ax1.xaxis.get_major_ticks()[1:-1])
>> ax1.plot(list(range(21)))
>> plt.show()
>>
>> Here is an example of the use of prune='lower', but it does not allow
>> one to set the tick step size:
>>
>> http://stackoverflow.com/questions/9422587/overlapping-y-axis-tick-label-and-x-axis-tick-label-in-matplotlib
>>
>> I think my best bet is to just set those ticks manually.
>>
>> On Sat, Feb 14, 2015 at 6:19 PM, Eric Firing <ef...@ha...> wrote:
>> > On 2015年02月14日 7:33 AM, Tommy Carstensen wrote:
>> >> Thanks again Ryan. That's exactly what I want to achieve; i.e. remove
>> >> the tick at 0 and only keep 5 and 10. Your solution works, but it's a
>> >> bit of hack to use magic constants. I could however get those values
>> >> from the xlim.
>> >>
>> >> Eric, I would describe the desired tick placement algorithm as
>> >> removing the first tick on the axis. It can be achieved like this:
>> >> ax1.xaxis.set_major_locator(MaxNLocator(prune='lower'))
>> >
>> > Aha! The problem is that the MaxNLocator is the only one with the prune
>> > kwarg. It could be added to the MultipleLocator. For now, though, you
>> > can make your own specialized Locator, hardwired to omit the first tick,
>> > like this:
>> >
>> > from matplotlib.ticker import MultipleLocator
>> >
>> > class TrimmedMultipleLocator(MultipleLocator):
>> > def tick_values(self, vmin, vmax):
>> > return MultipleLocator.tick_values(self, vmin, vmax)[1:]
>> >
>> > then just use
>> >
>> > ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5))
>> >
>> > I haven't tested it--but give it a try. What it is doing is making a
>> > subclass of MultipleLocator, and altering only the one little bit of its
>> > behavior that you want to modify. Everything else is automatically
>> > inherited from the base class, MultipleLocator.
>> >
>> > Eric
>> >
>> >
>> >>
>> >> But that then overrides this:
>> >> ax1.xaxis.set_major_locator(MultipleLocator(5))
>> >>
>> >> On Sat, Feb 14, 2015 at 5:27 PM, Ryan Nelson <rne...@gm...>
>> >> wrote:
>> >>> Tommy, (Sorry for the doubleup. I just realized I forgot to hit
>> >>> reply-all.)
>> >>>
>> >>> Do you want to remove the tick at 0 and only have 5,10, etc.? Could
>> >>> you just
>> >>> do something like this instead:
>> >>>
>> >>> import matplotlib.pyplot as plt
>> >>> from matplotlib.ticker import MultipleLocator
>> >>> fig = plt.figure()
>> >>> ax1 = fig.add_subplot(111)
>> >>> ax1.set_xticks(range(5,11,5))
>> >>> ax1.plot(range(11))
>> >>> plt.show()
>> >>>
>> >>> Ryan
>> >>>
>> >>>
>> >>> On Sat, Feb 14, 2015 at 10:47 AM, Tommy Carstensen
>> >>> <tom...@gm...> wrote:
>> >>>>
>> >>>> Thanks for you answer Eric. I had to get some sleep before trying out
>> >>>> things. I currently have the code below, but it does not remove the
>> >>>> zero value tick. It removes the tick at 5 and 10 however.
>> >>>>
>> >>>> import matplotlib.pyplot as plt
>> >>>> from matplotlib.ticker import MultipleLocator
>> >>>> fig = plt.figure()
>> >>>> ax1 = fig.add_subplot(111)
>> >>>> ax1.xaxis.set_major_locator(MultipleLocator(5))
>> >>>> xticks = ax1.xaxis.get_major_ticks()
>> >>>> #xticks[0].label1.set_visible(False)
>> >>>> #xticks[-1].label1.set_visible(False)
>> >>>> ax1.set_xticks(ax1.get_xticks()[1:-1])
>> >>>> ax1.plot(list(range(11)))
>> >>>> plt.show()
>> >>>>
>> >>>> On Sat, Feb 14, 2015 at 2:01 AM, Eric Firing <ef...@ha...>
>> >>>> wrote:
>> >>>>> On 2015年02月13日 3:29 PM, Tommy Carstensen wrote:
>> >>>>>> Is it possible to combine MultipleLocator and MaxNLocator? One
>> >>>>>> seems
>> >>>>>> to erase the effect of the other.
>> >>>>>
>> >>>>> They are for different situations. MultipleLocator is for when you
>> >>>>> know
>> >>>>> what you want your tick interval to be; MaxNLocator is for when you
>> >>>>> don't know that, but you do know roughly how many ticks you want,
>> >>>>> and
>> >>>>> what sort of numerical intervals are acceptable.
>> >>>>>
>> >>>>> Eric
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>> ------------------------------------------------------------------------------
>> >>>>> 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
>> >>>>> Mat...@li...
>> >>>>> 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
>> >>>> Mat...@li...
>> >>>> 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
>> >> Mat...@li...
>> >> 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
>> > Mat...@li...
>> > 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
>> Mat...@li...
>> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Tommy C. <tom...@gm...> - 2015年02月14日 19:15:48
Eric, it works if I do:
 return MultipleLocator.tick_values(self, vmin, vmax)[2:]
But not if I do as first suggested by you:
 return MultipleLocator.tick_values(self, vmin, vmax)[1:]
I don't understand this behaviour. It should be [1:]. I'll just set
the ticks manually. Seems to be the easiest thing. It would be
awesome, if MPL had the same behaviour as gnuplot, which allows me to
simply do:
set xtics <start>, <incr>
On Sat, Feb 14, 2015 at 7:09 PM, Eric Firing <ef...@ha...> wrote:
> On 2015年02月14日 8:45 AM, Tommy Carstensen wrote:
>>
>> Erik, that doesn't seem to work either. I tried this:
>>
>> import matplotlib.pyplot as plt
>> from matplotlib.ticker import MultipleLocator
>> class TrimmedMultipleLocator(MultipleLocator):
>> def tick_values(self, vmin, vmax):
>> return MultipleLocator.tick_values(self, vmin, vmax)[2:]
>> fig = plt.figure()
>> ax1 = fig.add_subplot(111)
>> ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5))
>> #xticks[0].label1.set_visible(False)
>> #xticks[-1].label1.set_visible(False)
>> #ax1.set_xticks(ax1.xaxis.get_major_ticks()[1:-1])
>> ax1.plot(list(range(21)))
>> plt.show()
>
>
> Are you sure? I tried it, and it works for me. See attached script and
> output.
>
> Eric
>
From: Eric F. <ef...@ha...> - 2015年02月14日 19:09:41
Attachments: test_loc.pdf test_loc.py
On 2015年02月14日 8:45 AM, Tommy Carstensen wrote:
> Erik, that doesn't seem to work either. I tried this:
>
> import matplotlib.pyplot as plt
> from matplotlib.ticker import MultipleLocator
> class TrimmedMultipleLocator(MultipleLocator):
> def tick_values(self, vmin, vmax):
> return MultipleLocator.tick_values(self, vmin, vmax)[2:]
> fig = plt.figure()
> ax1 = fig.add_subplot(111)
> ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5))
> #xticks[0].label1.set_visible(False)
> #xticks[-1].label1.set_visible(False)
> #ax1.set_xticks(ax1.xaxis.get_major_ticks()[1:-1])
> ax1.plot(list(range(21)))
> plt.show()
Are you sure? I tried it, and it works for me. See attached script and 
output.
Eric
From: Ryan N. <rne...@gm...> - 2015年02月14日 19:01:53
Tommy,
I'm sorry. I forgot to hit send all *again*. Below is my original message,
but the function I wrote is updated because it wasn't exactly correct....
Ah. I was working on something to help out, so I'm just seeing Eric's very
elegant solution, which I have yet to try. However, I feel like you might
run into some problems if you always drop the first tick. For example, try
this plot:
______________
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
import numpy as np
xs = np.linspace(2,12,1000)
ys = np.sin(xs)
n = 5
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(xs, ys)
ax1.xaxis.set_major_locator(MultipleLocator(5))
plt.show()
_____________
In this case, dropping the first tick will result in only one tick on the
screen.
What is your use-case? Are you annoyed that the axis labels are overlapping
at the far left? If that's the case, here's a little function (trimticks)
that I whipped up that might help. It drops the far left or far right label
if it is exactly at the edge of the axes. Should work for y axes as well.
_____________
def trimticks(ax, n=5):
 xmin, xmax = ax.get_xlim()
 if xmin%n == 0:
 xmin = xmin+n
 else:
 xmin = xmin + n - xmin%n
 if not xmax%n == 0:
 xmax = xmax + n - xmax%n
 ticks = np.arange(xmin, xmax, n)
 ax.set_xticks(ticks)
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
import numpy as np
xs = np.linspace(0,20,10000)
ys = np.sin(xs)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(xs, ys)
trimticks(ax1)
plt.show()
___________________
On Sat, Feb 14, 2015 at 1:45 PM, Tommy Carstensen <
tom...@gm...> wrote:
> Erik, that doesn't seem to work either. I tried this:
>
> import matplotlib.pyplot as plt
> from matplotlib.ticker import MultipleLocator
> class TrimmedMultipleLocator(MultipleLocator):
> def tick_values(self, vmin, vmax):
> return MultipleLocator.tick_values(self, vmin, vmax)[2:]
> fig = plt.figure()
> ax1 = fig.add_subplot(111)
> ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5))
> #xticks[0].label1.set_visible(False)
> #xticks[-1].label1.set_visible(False)
> #ax1.set_xticks(ax1.xaxis.get_major_ticks()[1:-1])
> ax1.plot(list(range(21)))
> plt.show()
>
> Here is an example of the use of prune='lower', but it does not allow
> one to set the tick step size:
>
> http://stackoverflow.com/questions/9422587/overlapping-y-axis-tick-label-and-x-axis-tick-label-in-matplotlib
>
> I think my best bet is to just set those ticks manually.
>
> On Sat, Feb 14, 2015 at 6:19 PM, Eric Firing <ef...@ha...> wrote:
> > On 2015年02月14日 7:33 AM, Tommy Carstensen wrote:
> >> Thanks again Ryan. That's exactly what I want to achieve; i.e. remove
> >> the tick at 0 and only keep 5 and 10. Your solution works, but it's a
> >> bit of hack to use magic constants. I could however get those values
> >> from the xlim.
> >>
> >> Eric, I would describe the desired tick placement algorithm as
> >> removing the first tick on the axis. It can be achieved like this:
> >> ax1.xaxis.set_major_locator(MaxNLocator(prune='lower'))
> >
> > Aha! The problem is that the MaxNLocator is the only one with the prune
> > kwarg. It could be added to the MultipleLocator. For now, though, you
> > can make your own specialized Locator, hardwired to omit the first tick,
> > like this:
> >
> > from matplotlib.ticker import MultipleLocator
> >
> > class TrimmedMultipleLocator(MultipleLocator):
> > def tick_values(self, vmin, vmax):
> > return MultipleLocator.tick_values(self, vmin, vmax)[1:]
> >
> > then just use
> >
> > ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5))
> >
> > I haven't tested it--but give it a try. What it is doing is making a
> > subclass of MultipleLocator, and altering only the one little bit of its
> > behavior that you want to modify. Everything else is automatically
> > inherited from the base class, MultipleLocator.
> >
> > Eric
> >
> >
> >>
> >> But that then overrides this:
> >> ax1.xaxis.set_major_locator(MultipleLocator(5))
> >>
> >> On Sat, Feb 14, 2015 at 5:27 PM, Ryan Nelson <rne...@gm...>
> wrote:
> >>> Tommy, (Sorry for the doubleup. I just realized I forgot to hit
> reply-all.)
> >>>
> >>> Do you want to remove the tick at 0 and only have 5,10, etc.? Could
> you just
> >>> do something like this instead:
> >>>
> >>> import matplotlib.pyplot as plt
> >>> from matplotlib.ticker import MultipleLocator
> >>> fig = plt.figure()
> >>> ax1 = fig.add_subplot(111)
> >>> ax1.set_xticks(range(5,11,5))
> >>> ax1.plot(range(11))
> >>> plt.show()
> >>>
> >>> Ryan
> >>>
> >>>
> >>> On Sat, Feb 14, 2015 at 10:47 AM, Tommy Carstensen
> >>> <tom...@gm...> wrote:
> >>>>
> >>>> Thanks for you answer Eric. I had to get some sleep before trying out
> >>>> things. I currently have the code below, but it does not remove the
> >>>> zero value tick. It removes the tick at 5 and 10 however.
> >>>>
> >>>> import matplotlib.pyplot as plt
> >>>> from matplotlib.ticker import MultipleLocator
> >>>> fig = plt.figure()
> >>>> ax1 = fig.add_subplot(111)
> >>>> ax1.xaxis.set_major_locator(MultipleLocator(5))
> >>>> xticks = ax1.xaxis.get_major_ticks()
> >>>> #xticks[0].label1.set_visible(False)
> >>>> #xticks[-1].label1.set_visible(False)
> >>>> ax1.set_xticks(ax1.get_xticks()[1:-1])
> >>>> ax1.plot(list(range(11)))
> >>>> plt.show()
> >>>>
> >>>> On Sat, Feb 14, 2015 at 2:01 AM, Eric Firing <ef...@ha...>
> wrote:
> >>>>> On 2015年02月13日 3:29 PM, Tommy Carstensen wrote:
> >>>>>> Is it possible to combine MultipleLocator and MaxNLocator? One seems
> >>>>>> to erase the effect of the other.
> >>>>>
> >>>>> They are for different situations. MultipleLocator is for when you
> know
> >>>>> what you want your tick interval to be; MaxNLocator is for when you
> >>>>> don't know that, but you do know roughly how many ticks you want, and
> >>>>> what sort of numerical intervals are acceptable.
> >>>>>
> >>>>> Eric
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> ------------------------------------------------------------------------------
> >>>>> 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
> >>>>> Mat...@li...
> >>>>> 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
> >>>> Mat...@li...
> >>>> 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
> >> Mat...@li...
> >> 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
> > Mat...@li...
> > 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Tommy C. <tom...@gm...> - 2015年02月14日 18:46:35
Erik, that doesn't seem to work either. I tried this:
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
class TrimmedMultipleLocator(MultipleLocator):
 def tick_values(self, vmin, vmax):
 return MultipleLocator.tick_values(self, vmin, vmax)[2:]
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5))
#xticks[0].label1.set_visible(False)
#xticks[-1].label1.set_visible(False)
#ax1.set_xticks(ax1.xaxis.get_major_ticks()[1:-1])
ax1.plot(list(range(21)))
plt.show()
Here is an example of the use of prune='lower', but it does not allow
one to set the tick step size:
http://stackoverflow.com/questions/9422587/overlapping-y-axis-tick-label-and-x-axis-tick-label-in-matplotlib
I think my best bet is to just set those ticks manually.
On Sat, Feb 14, 2015 at 6:19 PM, Eric Firing <ef...@ha...> wrote:
> On 2015年02月14日 7:33 AM, Tommy Carstensen wrote:
>> Thanks again Ryan. That's exactly what I want to achieve; i.e. remove
>> the tick at 0 and only keep 5 and 10. Your solution works, but it's a
>> bit of hack to use magic constants. I could however get those values
>> from the xlim.
>>
>> Eric, I would describe the desired tick placement algorithm as
>> removing the first tick on the axis. It can be achieved like this:
>> ax1.xaxis.set_major_locator(MaxNLocator(prune='lower'))
>
> Aha! The problem is that the MaxNLocator is the only one with the prune
> kwarg. It could be added to the MultipleLocator. For now, though, you
> can make your own specialized Locator, hardwired to omit the first tick,
> like this:
>
> from matplotlib.ticker import MultipleLocator
>
> class TrimmedMultipleLocator(MultipleLocator):
> def tick_values(self, vmin, vmax):
> return MultipleLocator.tick_values(self, vmin, vmax)[1:]
>
> then just use
>
> ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5))
>
> I haven't tested it--but give it a try. What it is doing is making a
> subclass of MultipleLocator, and altering only the one little bit of its
> behavior that you want to modify. Everything else is automatically
> inherited from the base class, MultipleLocator.
>
> Eric
>
>
>>
>> But that then overrides this:
>> ax1.xaxis.set_major_locator(MultipleLocator(5))
>>
>> On Sat, Feb 14, 2015 at 5:27 PM, Ryan Nelson <rne...@gm...> wrote:
>>> Tommy, (Sorry for the doubleup. I just realized I forgot to hit reply-all.)
>>>
>>> Do you want to remove the tick at 0 and only have 5,10, etc.? Could you just
>>> do something like this instead:
>>>
>>> import matplotlib.pyplot as plt
>>> from matplotlib.ticker import MultipleLocator
>>> fig = plt.figure()
>>> ax1 = fig.add_subplot(111)
>>> ax1.set_xticks(range(5,11,5))
>>> ax1.plot(range(11))
>>> plt.show()
>>>
>>> Ryan
>>>
>>>
>>> On Sat, Feb 14, 2015 at 10:47 AM, Tommy Carstensen
>>> <tom...@gm...> wrote:
>>>>
>>>> Thanks for you answer Eric. I had to get some sleep before trying out
>>>> things. I currently have the code below, but it does not remove the
>>>> zero value tick. It removes the tick at 5 and 10 however.
>>>>
>>>> import matplotlib.pyplot as plt
>>>> from matplotlib.ticker import MultipleLocator
>>>> fig = plt.figure()
>>>> ax1 = fig.add_subplot(111)
>>>> ax1.xaxis.set_major_locator(MultipleLocator(5))
>>>> xticks = ax1.xaxis.get_major_ticks()
>>>> #xticks[0].label1.set_visible(False)
>>>> #xticks[-1].label1.set_visible(False)
>>>> ax1.set_xticks(ax1.get_xticks()[1:-1])
>>>> ax1.plot(list(range(11)))
>>>> plt.show()
>>>>
>>>> On Sat, Feb 14, 2015 at 2:01 AM, Eric Firing <ef...@ha...> wrote:
>>>>> On 2015年02月13日 3:29 PM, Tommy Carstensen wrote:
>>>>>> Is it possible to combine MultipleLocator and MaxNLocator? One seems
>>>>>> to erase the effect of the other.
>>>>>
>>>>> They are for different situations. MultipleLocator is for when you know
>>>>> what you want your tick interval to be; MaxNLocator is for when you
>>>>> don't know that, but you do know roughly how many ticks you want, and
>>>>> what sort of numerical intervals are acceptable.
>>>>>
>>>>> Eric
>>>>>
>>>>>
>>>>>
>>>>> ------------------------------------------------------------------------------
>>>>> 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
>>>>> Mat...@li...
>>>>> 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
>>>> Mat...@li...
>>>> 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
>> Mat...@li...
>> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Eric F. <ef...@ha...> - 2015年02月14日 18:19:17
On 2015年02月14日 7:33 AM, Tommy Carstensen wrote:
> Thanks again Ryan. That's exactly what I want to achieve; i.e. remove
> the tick at 0 and only keep 5 and 10. Your solution works, but it's a
> bit of hack to use magic constants. I could however get those values
> from the xlim.
>
> Eric, I would describe the desired tick placement algorithm as
> removing the first tick on the axis. It can be achieved like this:
> ax1.xaxis.set_major_locator(MaxNLocator(prune='lower'))
Aha! The problem is that the MaxNLocator is the only one with the prune 
kwarg. It could be added to the MultipleLocator. For now, though, you 
can make your own specialized Locator, hardwired to omit the first tick, 
like this:
from matplotlib.ticker import MultipleLocator
class TrimmedMultipleLocator(MultipleLocator):
 def tick_values(self, vmin, vmax):
 return MultipleLocator.tick_values(self, vmin, vmax)[1:]
then just use
ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5))
I haven't tested it--but give it a try. What it is doing is making a 
subclass of MultipleLocator, and altering only the one little bit of its 
behavior that you want to modify. Everything else is automatically 
inherited from the base class, MultipleLocator.
Eric
>
> But that then overrides this:
> ax1.xaxis.set_major_locator(MultipleLocator(5))
>
> On Sat, Feb 14, 2015 at 5:27 PM, Ryan Nelson <rne...@gm...> wrote:
>> Tommy, (Sorry for the doubleup. I just realized I forgot to hit reply-all.)
>>
>> Do you want to remove the tick at 0 and only have 5,10, etc.? Could you just
>> do something like this instead:
>>
>> import matplotlib.pyplot as plt
>> from matplotlib.ticker import MultipleLocator
>> fig = plt.figure()
>> ax1 = fig.add_subplot(111)
>> ax1.set_xticks(range(5,11,5))
>> ax1.plot(range(11))
>> plt.show()
>>
>> Ryan
>>
>>
>> On Sat, Feb 14, 2015 at 10:47 AM, Tommy Carstensen
>> <tom...@gm...> wrote:
>>>
>>> Thanks for you answer Eric. I had to get some sleep before trying out
>>> things. I currently have the code below, but it does not remove the
>>> zero value tick. It removes the tick at 5 and 10 however.
>>>
>>> import matplotlib.pyplot as plt
>>> from matplotlib.ticker import MultipleLocator
>>> fig = plt.figure()
>>> ax1 = fig.add_subplot(111)
>>> ax1.xaxis.set_major_locator(MultipleLocator(5))
>>> xticks = ax1.xaxis.get_major_ticks()
>>> #xticks[0].label1.set_visible(False)
>>> #xticks[-1].label1.set_visible(False)
>>> ax1.set_xticks(ax1.get_xticks()[1:-1])
>>> ax1.plot(list(range(11)))
>>> plt.show()
>>>
>>> On Sat, Feb 14, 2015 at 2:01 AM, Eric Firing <ef...@ha...> wrote:
>>>> On 2015年02月13日 3:29 PM, Tommy Carstensen wrote:
>>>>> Is it possible to combine MultipleLocator and MaxNLocator? One seems
>>>>> to erase the effect of the other.
>>>>
>>>> They are for different situations. MultipleLocator is for when you know
>>>> what you want your tick interval to be; MaxNLocator is for when you
>>>> don't know that, but you do know roughly how many ticks you want, and
>>>> what sort of numerical intervals are acceptable.
>>>>
>>>> Eric
>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> 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
>>>> Mat...@li...
>>>> 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
>>> Mat...@li...
>>> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Tommy C. <tom...@gm...> - 2015年02月14日 17:34:02
Thanks again Ryan. That's exactly what I want to achieve; i.e. remove
the tick at 0 and only keep 5 and 10. Your solution works, but it's a
bit of hack to use magic constants. I could however get those values
from the xlim.
Eric, I would describe the desired tick placement algorithm as
removing the first tick on the axis. It can be achieved like this:
ax1.xaxis.set_major_locator(MaxNLocator(prune='lower'))
But that then overrides this:
ax1.xaxis.set_major_locator(MultipleLocator(5))
On Sat, Feb 14, 2015 at 5:27 PM, Ryan Nelson <rne...@gm...> wrote:
> Tommy, (Sorry for the doubleup. I just realized I forgot to hit reply-all.)
>
> Do you want to remove the tick at 0 and only have 5,10, etc.? Could you just
> do something like this instead:
>
> import matplotlib.pyplot as plt
> from matplotlib.ticker import MultipleLocator
> fig = plt.figure()
> ax1 = fig.add_subplot(111)
> ax1.set_xticks(range(5,11,5))
> ax1.plot(range(11))
> plt.show()
>
> Ryan
>
>
> On Sat, Feb 14, 2015 at 10:47 AM, Tommy Carstensen
> <tom...@gm...> wrote:
>>
>> Thanks for you answer Eric. I had to get some sleep before trying out
>> things. I currently have the code below, but it does not remove the
>> zero value tick. It removes the tick at 5 and 10 however.
>>
>> import matplotlib.pyplot as plt
>> from matplotlib.ticker import MultipleLocator
>> fig = plt.figure()
>> ax1 = fig.add_subplot(111)
>> ax1.xaxis.set_major_locator(MultipleLocator(5))
>> xticks = ax1.xaxis.get_major_ticks()
>> #xticks[0].label1.set_visible(False)
>> #xticks[-1].label1.set_visible(False)
>> ax1.set_xticks(ax1.get_xticks()[1:-1])
>> ax1.plot(list(range(11)))
>> plt.show()
>>
>> On Sat, Feb 14, 2015 at 2:01 AM, Eric Firing <ef...@ha...> wrote:
>> > On 2015年02月13日 3:29 PM, Tommy Carstensen wrote:
>> >> Is it possible to combine MultipleLocator and MaxNLocator? One seems
>> >> to erase the effect of the other.
>> >
>> > They are for different situations. MultipleLocator is for when you know
>> > what you want your tick interval to be; MaxNLocator is for when you
>> > don't know that, but you do know roughly how many ticks you want, and
>> > what sort of numerical intervals are acceptable.
>> >
>> > Eric
>> >
>> >
>> >
>> > ------------------------------------------------------------------------------
>> > 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
>> > Mat...@li...
>> > 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
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
From: Tommy C. <tom...@gm...> - 2015年02月14日 17:28:56
Whoa, thanks for a great answer Ryan. I can see, why the level of
control MPL gives you is a great sales pitch. It's one of the reasons,
why I switched from gnuplot after using it for many years and making
many cool plots. The MPL learning curve has just been a bit steep,
when you are used to plot whatever you want.
On Sat, Feb 14, 2015 at 5:06 PM, Ryan Nelson <rne...@gm...> wrote:
> Tommy,
>
> I'll try to answer your points in order:
>
> 1) Oops. That should have been "xticks".
> import matplotlib.pyplot as plt
> plt.plot([1,3,2])
> ticks, labels = plt.xticks()
> plt.xticks(ticks, horizontalalignment='left')
> plt.show()
>
>
> 2) Sorry for the ambiguity. "OO" is short for object-oriented. There are two
> different approaches that people tend to use to make plots (although they
> can be mixed): 1) the "pyplot" way, which uses the pyplot wrapper functions
> and 2) the object-oriented way, which modifies the objects directly. This is
> what you did in your example where you snag the axes objects and operate on
> them directly. The "OO" way is ultimately more powerful, because the pyplot
> wrapper functions override some of your control. For example, because you
> want twin axes, you might not be able to use the pyplot.xticks function
> (Others, correct me if I'm wrong.), and you lose some fine control. See next
> example.
>
> 3) I know it *seems* like the for loop is an "ugly hack". However, you have
> to realize that this ultimately gives you a TON of control. Let's say, for
> example, that you wanted only one of the labels to be large and red to
> highlight a certain value. Using a modified version of your example, we get
> this:
> ______________
> import matplotlib.pyplot as plt
> fig = plt.figure()
> ax1 = fig.add_subplot(111)
> ax2 = ax1.twinx()
> labels = ax2.yaxis.get_ticklabels()
> [l.set_horizontalalignment('right') for l in labels]
> labels[2].set_color('red')
> labels[2].set_fontsize(20)
> ax2.tick_params(pad=20)
> ax1.plot(list(range(11)))
> ax1.set_xlim(0,10)
> ax2.set_ylim(0,10)
> plt.show()
> ____________
> I personally think that this level of control is very, very cool and one of
> the big selling points for MPL in general.
>
> Okay. If you want to set the alignment all the time, there might be a way to
> control this with matplotlibrc or style sheets:
> http://matplotlib.org/users/customizing.html
> http://matplotlib.org/users/style_sheets.html
> However, I'm not the biggest fan of changing matplotlibrc. Mostly because if
> others try to reproduce your plots, they also need your rc file as well. I
> haven't used style sheets yet, but that might be a fix to this issue (for me
> at least).
>
> Hope that helps.
>
> Ryan
>
> On Sat, Feb 14, 2015 at 10:30 AM, Tommy Carstensen
> <tom...@gm...> wrote:
>>
>> 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 <rne...@gm...>
>> 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
>> > <tom...@gm...> 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
>> >> Mat...@li...
>> >> 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
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
From: Ryan N. <rne...@gm...> - 2015年02月14日 17:27:41
Tommy, (Sorry for the doubleup. I just realized I forgot to hit reply-all.)
Do you want to remove the tick at 0 and only have 5,10, etc.? Could you
just do something like this instead:
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.set_xticks(range(5,11,5))
ax1.plot(range(11))
plt.show()
Ryan
On Sat, Feb 14, 2015 at 10:47 AM, Tommy Carstensen <
tom...@gm...> wrote:
> Thanks for you answer Eric. I had to get some sleep before trying out
> things. I currently have the code below, but it does not remove the
> zero value tick. It removes the tick at 5 and 10 however.
>
> import matplotlib.pyplot as plt
> from matplotlib.ticker import MultipleLocator
> fig = plt.figure()
> ax1 = fig.add_subplot(111)
> ax1.xaxis.set_major_locator(MultipleLocator(5))
> xticks = ax1.xaxis.get_major_ticks()
> #xticks[0].label1.set_visible(False)
> #xticks[-1].label1.set_visible(False)
> ax1.set_xticks(ax1.get_xticks()[1:-1])
> ax1.plot(list(range(11)))
> plt.show()
>
> On Sat, Feb 14, 2015 at 2:01 AM, Eric Firing <ef...@ha...> wrote:
> > On 2015年02月13日 3:29 PM, Tommy Carstensen wrote:
> >> Is it possible to combine MultipleLocator and MaxNLocator? One seems
> >> to erase the effect of the other.
> >
> > They are for different situations. MultipleLocator is for when you know
> > what you want your tick interval to be; MaxNLocator is for when you
> > don't know that, but you do know roughly how many ticks you want, and
> > what sort of numerical intervals are acceptable.
> >
> > Eric
> >
> >
> >
> ------------------------------------------------------------------------------
> > 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
> > Mat...@li...
> > 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Eric F. <ef...@ha...> - 2015年02月14日 17:17:23
On 2015年02月14日 5:47 AM, Tommy Carstensen wrote:
> Thanks for you answer Eric. I had to get some sleep before trying out
> things. I currently have the code below, but it does not remove the
> zero value tick. It removes the tick at 5 and 10 however.
What is the effect you are trying to achieve? How would you describe 
the desired tick placement algorithm?
Eric
>
> import matplotlib.pyplot as plt
> from matplotlib.ticker import MultipleLocator
> fig = plt.figure()
> ax1 = fig.add_subplot(111)
> ax1.xaxis.set_major_locator(MultipleLocator(5))
> xticks = ax1.xaxis.get_major_ticks()
> #xticks[0].label1.set_visible(False)
> #xticks[-1].label1.set_visible(False)
> ax1.set_xticks(ax1.get_xticks()[1:-1])
> ax1.plot(list(range(11)))
> plt.show()
>
> On Sat, Feb 14, 2015 at 2:01 AM, Eric Firing <ef...@ha...> wrote:
>> On 2015年02月13日 3:29 PM, Tommy Carstensen wrote:
>>> Is it possible to combine MultipleLocator and MaxNLocator? One seems
>>> to erase the effect of the other.
>>
>> They are for different situations. MultipleLocator is for when you know
>> what you want your tick interval to be; MaxNLocator is for when you
>> don't know that, but you do know roughly how many ticks you want, and
>> what sort of numerical intervals are acceptable.
>>
>> Eric
>>
>>
>> ------------------------------------------------------------------------------
>> 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
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Ryan N. <rne...@gm...> - 2015年02月14日 17:06:53
Tommy,
I'll try to answer your points in order:
1) Oops. That should have been "xticks".
import matplotlib.pyplot as plt
plt.plot([1,3,2])
ticks, labels = plt.xticks()
plt.xticks(ticks, horizontalalignment='left')
plt.show()
2) Sorry for the ambiguity. "OO" is short for object-oriented. There are
two different approaches that people tend to use to make plots (although
they can be mixed): 1) the "pyplot" way, which uses the pyplot wrapper
functions and 2) the object-oriented way, which modifies the objects
directly. This is what you did in your example where you snag the axes
objects and operate on them directly. The "OO" way is ultimately more
powerful, because the pyplot wrapper functions override some of your
control. For example, because you want twin axes, you might not be able to
use the pyplot.xticks function (Others, correct me if I'm wrong.), and you
lose some fine control. See next example.
3) I know it *seems* like the for loop is an "ugly hack". However, you have
to realize that this ultimately gives you a TON of control. Let's say, for
example, that you wanted only one of the labels to be large and red to
highlight a certain value. Using a modified version of your example, we get
this:
______________
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
labels = ax2.yaxis.get_ticklabels()
[l.set_horizontalalignment('right') for l in labels]
labels[2].set_color('red')
labels[2].set_fontsize(20)
ax2.tick_params(pad=20)
ax1.plot(list(range(11)))
ax1.set_xlim(0,10)
ax2.set_ylim(0,10)
plt.show()
____________
I personally think that this level of control is very, very cool and one of
the big selling points for MPL in general.
Okay. If you want to set the alignment all the time, there might be a way
to control this with matplotlibrc or style sheets:
http://matplotlib.org/users/customizing.html
http://matplotlib.org/users/style_sheets.html
However, I'm not the biggest fan of changing matplotlibrc. Mostly because
if others try to reproduce your plots, they also need your rc file as well.
I haven't used style sheets yet, but that might be a fix to this issue (for
me at least).
Hope that helps.
Ryan
On Sat, Feb 14, 2015 at 10:30 AM, Tommy Carstensen <
tom...@gm...> wrote:
> 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 <rne...@gm...>
> 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
> > <tom...@gm...> 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
> >> Mat...@li...
> >> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Tommy C. <tom...@gm...> - 2015年02月14日 15:48:31
Thanks for you answer Eric. I had to get some sleep before trying out
things. I currently have the code below, but it does not remove the
zero value tick. It removes the tick at 5 and 10 however.
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.xaxis.set_major_locator(MultipleLocator(5))
xticks = ax1.xaxis.get_major_ticks()
#xticks[0].label1.set_visible(False)
#xticks[-1].label1.set_visible(False)
ax1.set_xticks(ax1.get_xticks()[1:-1])
ax1.plot(list(range(11)))
plt.show()
On Sat, Feb 14, 2015 at 2:01 AM, Eric Firing <ef...@ha...> wrote:
> On 2015年02月13日 3:29 PM, Tommy Carstensen wrote:
>> Is it possible to combine MultipleLocator and MaxNLocator? One seems
>> to erase the effect of the other.
>
> They are for different situations. MultipleLocator is for when you know
> what you want your tick interval to be; MaxNLocator is for when you
> don't know that, but you do know roughly how many ticks you want, and
> what sort of numerical intervals are acceptable.
>
> Eric
>
>
> ------------------------------------------------------------------------------
> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Tommy C. <tom...@gm...> - 2015年02月14日 15:31:19
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 <rne...@gm...> 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
> <tom...@gm...> 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
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
From: Virgil S. <vs...@it...> - 2015年02月14日 10:33:27
On 14-Feb-2015 02:29, Tommy Carstensen wrote:
> Is it possible to combine MultipleLocator and MaxNLocator? One seems
> to erase the effect of the other.
>
> ------------------------------------------------------------------------------
> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Tommy,
Perhaps you might find it useful to look at the Python class that Justin Talbot 
wrote (http://www.justintalbot.com/research/axis-labeling/). I find this very 
useful in my own work.
From: Eric F. <ef...@ha...> - 2015年02月14日 02:01:57
On 2015年02月13日 3:29 PM, Tommy Carstensen wrote:
> Is it possible to combine MultipleLocator and MaxNLocator? One seems
> to erase the effect of the other.
They are for different situations. MultipleLocator is for when you know 
what you want your tick interval to be; MaxNLocator is for when you 
don't know that, but you do know roughly how many ticks you want, and 
what sort of numerical intervals are acceptable.
Eric
From: Tommy C. <tom...@gm...> - 2015年02月14日 01:29:50
Is it possible to combine MultipleLocator and MaxNLocator? One seems
to erase the effect of the other.
From: Tommy C. <tom...@gm...> - 2015年02月14日 00:29:57
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.

Showing 25 results of 25

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /