Brilliant! That actually worked thanks. Indexformatter gave me terrible 
problems subsequently, not working when the ticks were too large in value. 
FixedFormat seems to work better. Here's an updated form of that code
============================================
import matplotlib.ticker

#function to make life easier
def latex_ticklabels(lbls_x,lbls_y):
    #need to prefix empty string to labels for some reason(Don't know 
myself).
    return 
[matplotlib.ticker.FixedFormatter(lbls_x),matplotlib.ticker.FixedFormatter(lbls_y)]

#the labels we are going to use (Must match number of ticks I think)
x_labels=["$x_1$","$x_2$"]
y_labels=["$y_1$","$y_2$","$y_3$"]

P0=plot(x^2,(r,0,2),ticks=[[1,2],[0.5,2.4,3]],tick_formatter=latex_ticklabels(x_labels,y_labels),fontsize=15)

show(P0)
============================================

In desperation, I was also working on a method of (simply?) using text 
labels at each tick. I'll include it here for people who have trouble 
getting matplotlib to work

============================================
import matplotlib.ticker


x_ticks=[1,8]
x_labels=["$x_1$","$x_2$"]

y_ticks=[6,16,60]
y_labels=["$y_1$","$y_2$","$y_3$"]

P0=plot(x^2,(r,0,8),ticks=[x_ticks,y_ticks],tick_formatter=[matplotlib.ticker.NullFormatter(),matplotlib.ticker.NullFormatter()])

x_offset=1
PX_LABELS=sum( 
[text(x_label,(x_tick,-x_offset),color="black",vertical_alignment="top",fontsize=15)
 
for [x_tick,x_label] in zip(x_ticks,x_labels)])

y_offset=0.03
PY_LABELS=sum( 
[text(y_label,(-y_offset,y_tick),color="black",horizontal_alignment="right",fontsize=15)
 
for [y_tick,y_label] in zip(y_ticks,y_labels)])

show(P0+PX_LABELS+PY_LABELS)

============================================


I think that such functionality should eventually be part of plot by 
default.

On Friday, June 1, 2012 7:50:19 PM UTC+1, Michael Orlitzky wrote:
>
> On 06/01/12 13:26, ObsessiveMathsFreak wrote: 
> > 
> > The problem is that if the tick marks are too close together, the labels 
> > repeat themselves, or seem not to appear. It's very frustrating.  For 
> > example try 
> > 
> > 
> P0=plot(x^2,(r,0,2),ticks=[[1,2],[0.5,1]],tick_formatter=latex_ticklabels(x_labels,y_labels),fontsize=15)
>  
>
> > show(P0) 
> > 
> > Anyway, hopefully this will work for now. 
>
> Try FixedFormatter instead of IndexFormatter. I had better results with 
> it (although it occasionally seems off-by-one?). 
>

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to