Adding Greek Characters To Plots

Ben Abbott bpabbott at mac.com
Wed Oct 15 19:15:00 CDT 2008


On Oct 15, 2008, at 3:57 PM, David Bateman wrote:

> Ben Abbott wrote:
>> On Wednesday, October 15, 2008, at 02:39PM, "John W. Eaton" <jwe at bevo.che.wisc.edu 
>> > wrote:
>>> The following works for me with the current development sources:
>>>
>>> axis ([-pi, pi, 0, 1]);
>>> set (gca, 'fontname', 'symbol')
>>> set (gca, 'xtick', [-pi, -pi/2, 0, pi/2, pi])
>>> set (gca, 'xticklabel', {'-p', '-p/2', '0', 'p/2', 'p'})
>>>
>>> and I think this is compatible behavior.  However, it does not seem
>>> like a good general solution to me as I don't see how you would mix
>>> symbol and non-symbol 'p' this way.  Also, shouldn't we be able to  
>>> use
>>> TeX notation in the tick labels to avoid that problem?  That doesn't
>>> work for me.
>>>
>>> jwe
>> I agree it is compatible behavior. Unfortunately for me, my gnuplot  
>> doesn't handle the symbol font correctly.
>> I also agree it is not a good solution. Do you suggest we deviate  
>> from Matlab's approach? ... perhaps we should add an "interpreter"  
>> property to the axes? (that it is missing in Matlab is a long  
>> frustration for me).
>
> I can't test this at the moment, but is it really the compatible  
> behavior? The "Right (TM)" way to do this would be to replace [x|y| 
> z]ticklabel with a text object in the same manner as [x|y|z]label of  
> the axes are. However, that certainly isn't compatible.
>
> I also don't think its a good idea to include a an interpreter  
> property in the axes object itself..
>
> Maybe a reasonable hack would be just to assume that the interpreter  
> property for the ticks are set to "tex" and munge the text for the  
> ticks with
>
> for i = 1 : numel(labels)
> labels{i} = __tex2enhanced__ (labels{i}, "Helvetica", false, false);
> endfor
>
> at the appropriate place in "__go_draw_axes__.m (do_tics_1)".
>
> D.

David, thanks for letting me handle this change. I've learned a  
bit ... in particular, I learned how simple it was to make the  
change ;-)

The change to __go_draw_axes__.m defaults to "tex" if there is not  
axes property for "interpreter". That way you can see it at work. Once  
the axes have an interpreter property the if-block in __go_draw_axes__  
(do_tics) may be deleted ... or left as it is.

A simple example of its use is below

x = pi * (0:10)/10;
xtick = [0:0.25:1.01]*pi;
xticklabel = {'0', '\pi/4', '\pi/2', '3\pi/4', '\pi'};
figure(1)
clf
axes();
plot (x,sin(x))
set (gca, "xtick", xtick, "xticklabel", xticklabel)
xlim ([0, pi])

If a subsequent newplot is made to the axis the ticklabels are reset  
to their default values (as is done in Matlab). I suggest the  
interpreter value do the same (which it would unless newplot() is  
modified).

Ben

-------------- next part --------------
A non-text attachment was scrubbed...
Name: changeset-interpreter_for_axes.patch
Type: application/octet-stream
Size: 4868 bytes
Desc: not available
Url : https://www-old.cae.wisc.edu/pipermail/help-octave/attachments/20081015/474dfb27/attachment-0001.obj 
-------------- next part --------------









More information about the Help-octave mailing list