matlab2tikz library question
이전 댓글 표시
I am trying to use high quality matlab figures in tikz format. Currently I have added customized labels as seen in Matlab figure below:

Below is the matlab code
x=[ 512*512 1024*1024 2048*2048 3072*3072 4096*4096 5120*5120];
y1=[27.66 29.82 30.41 30.43 30.55 30.6]
y2=[28.93 33.30 36.13 36.48 37.50 38.28];
y3=[29.28 34.49 39.23 40.17 43.01 46.80];
figure
set(gca,'xTick', [ 512*512 1024*1024, 2048*2048, 3072*3072, 4096*4096, 5120*5120]);
set(gca,'xTickLabel', {'512x512', '1024x1024', '2048x2048', '3072x3072', '4096x4096', '5120x5120'});
set(gca,'XTickLabelRotation',45)
hold on
plot(x,y1);
hold on
plot(x,y2);
hold on
plot(x,y3)
hold on
However, I export it to .tikz file using matlab2tikz library and use it in latex. I am facing three issues that are :
- The labels '512x512', '1024x1024' are shifted forwards as seen in below snapshot taken from latex, hence it points to a wrong value
- The above labels overlap with 'Atlas image resolution' label of x axis.
- The value 10 to the power of 7 appear from nowhere in latex. I checked the tikz file it does not have 10 to the power 7 value.

Please help me with this. I have attached the tikz file content into a text file.
ga59siv @ matlab . rbg . tum . de
답변 (1개)
Star Strider
2016년 12월 26일
The ‘10^7’ is coming from the way you define ‘x’. The actual values of ‘x’ are:
x =
262.1440e+003 1.0486e+006 4.1943e+006 9.4372e+006 16.7772e+006 26.2144e+006
For the x-label, experiment with different values for 'FontSize', for example:
set(gca,'XTickLabelRotation',45, 'FontSize',8)
댓글 수: 4
Prajwal Sapare
2016년 12월 27일
Star Strider
2016년 12월 27일
Actually, they’re not shifted. They’re aligned by the centres of the labels. If you want them aligned by the right border of the object, you have to use the text function.
The Code:
x=[ 512*512 1024*1024 2048*2048 3072*3072 4096*4096 5120*5120]
y1=[27.66 29.82 30.41 30.43 30.55 30.6];
y2=[28.93 33.30 36.13 36.48 37.50 38.28];
y3=[29.28 34.49 39.23 40.17 43.01 46.80];
figure
hold on
semilogx(x,y1);
hold on
plot(x,y2);
plot(x,y3)
hold off
set(gca, 'XTickLabel',[])
set(gca,'xTick', [ 512*512 1024*1024, 2048*2048, 3072*3072, 4096*4096, 5120*5120]);
xloc = [ 512*512 1024*1024, 2048*2048, 3072*3072, 4096*4096, 5120*5120];
text(xloc, min(ylim)-0.5*ones(size(xloc)), {'512x512', '1024x1024', '2048x2048', '3072x3072', '4096x4096', '5120x5120'}, 'Rotation',45, 'HorizontalAlignment','right', 'FontSize',8)
Experiment with that to get the exact result you want.
Prajwal Sapare
2016년 12월 27일
Star Strider
2016년 12월 27일
편집: Star Strider
2016년 12월 29일
EDIT — (28 Dec 2016 00:25 UCT)
With a bit of help from MathWorks Tech Support (and some tweaking of the solution the provided in order to get it to work correctly), I can provide code that now works.
The Code:
x=[ 512*512 1024*1024 2048*2048 3072*3072 4096*4096 5120*5120];
y1=[27.66 29.82 30.41 30.43 30.55 30.6];
y2=[28.93 33.30 36.13 36.48 37.50 38.28];
y3=[29.28 34.49 39.23 40.17 43.01 46.80];
figure
hold on
semilogx(x,y1);
hold on
plot(x,y2);
plot(x,y3)
hold off
set(gca, 'XTickLabel',[])
set(gca,'xTick', [ 512*512 1024*1024, 2048*2048, 3072*3072, 4096*4096, 5120*5120]);
xloc = [ 512*512 1024*1024, 2048*2048, 3072*3072, 4096*4096, 5120*5120];
text(xloc, min(ylim)-0.5*ones(size(xloc)), {'512x512', '1024x1024', '2048x2048', '3072x3072', '4096x4096', '5120x5120'}, 'Rotation',45, 'HorizontalAlignment','right', 'FontSize',8)
xlabel('Atlas Image Resolution')
opos = get(gca, 'OuterPosition');
set(gca, 'OuterPosition', [0 0.15 1 0.85], 'Units','pixel')
xlbl = get(gca, 'XLabel');
set(xlbl,'Position',[15E+6 20 0], 'String','Atlas Image Resolution')
My error was in believing this was figure property rather than an axis property. Experiment with it to get the result you want.
The Plot:

카테고리
도움말 센터 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!