|
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
|