Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Virgil Stokes
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

Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Tommy Carstensen
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

Re: [Matplotlib-users] horizontal alignment of a secondary y-axis

2015-02-14 Thread Tommy Carstensen
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

Re: [Matplotlib-users] horizontal alignment of a secondary y-axis

2015-02-14 Thread Tommy Carstensen
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

Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Ryan Nelson
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 =

Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Eric Firing
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

Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Ryan Nelson
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

Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Eric Firing
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

Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Tommy Carstensen
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 =

Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Tommy Carstensen
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

Re: [Matplotlib-users] horizontal alignment of a secondary y-axis

2015-02-14 Thread Ryan Nelson
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

Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Eric Firing
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

Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Tommy Carstensen
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

Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Tommy Carstensen
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

Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Eric Firing
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

Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Tommy Carstensen
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

Re: [Matplotlib-users] horizontal alignment of a secondary y-axis

2015-02-14 Thread Tommy Carstensen
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

Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Ryan Nelson
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

Re: [Matplotlib-users] horizontal alignment of a secondary y-axis

2015-02-14 Thread Tommy Carstensen
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)

Re: [Matplotlib-users] MultipleLocator and MaxNLocator

2015-02-14 Thread Tommy Carstensen
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 efir...@hawaii.edu wrote: On 2015/02/14 9:15 AM, Tommy Carstensen wrote: Eric,

Re: [Matplotlib-users] horizontal alignment of a secondary y-axis

2015-02-14 Thread Ryan Nelson
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