Print a Figure with two Y-Axes - displaced coordinate systems

I got o problem with a figure where there are two Y-Axes. When I am in the print preview layout, I can see the coordinate system fitting well.
However, when I do print the figure, two coordinate systems are appearing and they are shifted, and the labels, ticks and curves are not matching any more. It looks like these coordinate systems are displaced, which has not appeared in the print preview.
Is there a way to fix it?
I am basically using this code:
figure(3)
% Plot V Nits and Temp Black Body with two Y-Axes
[AX,H1,H2] = plotyy(x,v_original,x,t_bb);
% Set Axis names & Grid on
% left Y-Axis
% set label
set(get(AX(1),'Ylabel'),'String','U_A [\mu V]', 'Color', 'black')
% set Axis values
set(AX(1),'YLim', [-50000 50000], 'YTick', -50000:10000:50000);
% right Y-Axis
% set label
set(get(AX(2),'Ylabel'),'String','Temperature[°C]', 'Color', 'black')
% set Axis values
set(AX(2),'YLim', [-50 50],'YTick', -50:5:50);
grid on;
% Set Curves color
% for V_original = Voltage THERMOPILE
set(H1,'Color',[0 0 0], 'LineStyle', '-');
% for T_bb = Temperature Blackbody
set(H2,'Color','red', 'LineStyle', '--', 'LineWidth', 2);
hold on
% mean values
H3 = bar(x,v_mean);
set(H3,'FaceColor',[.96 .92 .92], 'EdgeColor','none');
% median values
H4 = bar(x,v_median);
set(H4,'FaceColor',[.89 .94 .9], 'EdgeColor','none');
% standard deviation
H5 = bar(x,v_sd);
set(H5,'FaceColor',[.87 .92 .98], 'EdgeColor','none');
% Enable 2nd Y-Axis so multiple plots can be drawn
% depending on that scale
set(AX(2),'nextplot','add');
% temperature NITS
H6 = plot(AX(2),x, t_nits);
set(H6,'Color','green', 'LineStyle', '--', 'LineWidth', 2);
% Enable 2nd Y-Axis so multiple plots can be drawn
% depending on that scale
set(AX(2),'nextplot','add');
% temperature Amb
H7 = plot(AX(2),x, t_amb);
set(H7,'Color','blue', 'LineStyle', '--', 'LineWidth', 2);
title('T_A_m_b = -5°C');
xlabel('Zeit \tau in [s]');
legend('V_A', 'V_M_e_a_n', 'V_M_e_d_i_a_n', 'V_S_t_a_n_d_a_r_d', 'T_B_B', 'T_n_i_t_s', 'T_a_m_b', 'location', 'NorthWest');
hold off

4 comentarios

FYI, you can write your legend entries like this: 'V_{Median}' instead of this: 'V_M_e_d_i_a_n' ... might save you a few keystokes.
thank you for that hint.
How do you print? Simply "print -djpeg figureprinted.jpg"? I ran your code with some data and got a nice result ...
I am printing via the interactive Menu:
File - Print Preview - Print
I have already tried if the Orientation, the paper style or something else matters - unfortunately I always end up in the same result with the displaced coordinate systems.

Iniciar sesión para comentar.

Respuestas (1)

This is just a guess, but you could try doing this at the end of your code:
set(AX, 'ActivePositionProperty', 'position');
where AX is the array hold the two axes handles.

2 comentarios

unfortunately, that is not working.
This works if you print from command line, like Titus Edelhofer said! Thanks for the hint Patrick!

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 4 de En. de 2012

Comentada:

el 27 de Nov. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by