how to use fraction and symbols in yticklabel?

조회 수: 40 (최근 30일)
Julie
Julie 2014년 12월 18일
편집: Walter Roberson 2017년 10월 6일
I want a plot to have units of \frac{e^2}{2\hbar} in stead of 1, 2, 3,...
But I can only insert the math symbols in an ordinary label and not in a yticklabel.
The plot should have an y-axis with the values 0, \frac{e^2}{2\hbar}, 2 \frac{e^2}{2\hbar}.
How do I use the yticklabel with math symbols?
figure
plot(xdata,ydata)
set(gca,'ytick',[0, 1, 2])
set(gca,'yticklabel',{'0','$$\frac{e^2}{2\hbar}$$','$$2 \frac{e^2}{2\hbar}$$','Interpreter','latex'},'FontSize',13)
title('The conductivity','Fontsize',15),
xlabel('Photon energy [eV]','Fontsize',13)
  댓글 수: 1
hamed shorakaei
hamed shorakaei 2017년 10월 6일
The following style is work for labeling. Please use it for your purpose.
ylabel('$\displaystyle\frac{e^2}{2\hbar}$','interpreter','latex')

댓글을 달려면 로그인하십시오.

채택된 답변

Orion
Orion 2014년 12월 18일
you can't use latex in yticklabel (unfortunately). you're gonna have to use text if you really want to insert math symbols.
something like :
clear all
figure
xdata = 0:0.01:10;
ydata = sin(2*xdata)+1;
plot(xdata,ydata)
set(gca,'ytick',[0, 1, 2],'yticklabel',[])
tt(1) = text(-0.5,0,'0');
tt(2) = text(-0.5,1,'$$\frac{e^2}{2\hbar}$$');
tt(3) = text(-0.5,2,'$$2 \frac{e^2}{2\hbar}$$');
set(tt,'Interpreter','latex');

추가 답변 (1개)

dan halbersberg
dan halbersberg 2016년 1월 30일
There is a way but you need to use the 'TickLabelInterpreter' property. Here is an example:
figure()
a = axes;
plot(xdata,ydata);
set(gca,'YTick',[0, 1, 2]);
set(a,'TickLabelInterpreter','latex');
set(gca,'YTickLabel',{'0','$$\frac{\textrm{e^2}}{\textrm{2\hbar}}$$','$$2 \frac{\textrme^3}}{\textrm{2\hbar}}$$'});
ylabel('\bf{Y values}','fontsize',14);
xlabel('\bf{X}','fontsize',14);
  댓글 수: 1
Walter Roberson
Walter Roberson 2016년 1월 30일
Note: YTickLabelInterpreter is new as of R2014b

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by