Issues getting dual y-axis ticks/values to line up

1 visualización (últimos 30 días)
Adam Goldsmith
Adam Goldsmith el 15 de Jun. de 2015
Comentada: Adam Goldsmith el 16 de Jun. de 2015
I'm making a figure with two y-axes which are mutually a power law function of each other. What I want is for the y-axis ticks on the right to display their equivalent values from the right y-axis; that is, for each tick on the right y-axis I want a corresponding tick with its equivalent value on the left y-axis.
Here's the code that I've written for the figure. Note that I plot a third (empirically measured) variable as a dashed line across the plot:
figure(14)
title(['EDDR and T_{c} vs Temperature for ' sample_name])
[fig14,ax1,ax2] = plotyy([min(realTC) max(realTC)],[esr esr],realTC,Tc_EDDR,@line,@line);
set(ax1,'LineWidth',1.5,'Color','k','LineStyle','--')
set(ax2,'LineWidth',1,'Color','k','LineStyle','-')
set(fig14(1),'YColor','k','LineWidth',1)
set(fig14(2),'YColor','k','LineWidth',1)
xlabel('Temperature (°C)')
fig14(1).YLabel.String = 'Estimated Diffusion Domain Size (\mum)';
fig14(2).YLabel.String = 'Closure temperature (°C, \deltaT/\deltat = 10 °C/m.y.)';
fig14y2 = 50:20:250; % Tc values of ticks on left y-axis
set(fig14(2),'YLim',[min(fig14y2) max(fig14y2)],'YTick',fig14y2) % forces ticks on left y-axis
EDDRTc = polyfit(log(EDDR),log(Tc_EDDR),1); % solves for loglog EDDR v Tc curve as linear
fig14y1 = exp((log(fig14y2) - EDDRTc(2))/EDDRTc(1)); % solve for equivalent EDDR values of Tc ticks
set(fig14(1),'LineWidth',1,'YLim',[min(fig14y1) max(fig14y1)],'YTick',fig14y1) % forces ticks on right y-axis
legend('Observed equivalent spherical radius','Estimated diffusion domain radius')
I've attached a photo of the result, it's not quite what I was going for. Any ideas as to how to get this damn thing to work? Also, how do I limit the number of significant digits on the right y-axis to three?

Respuesta aceptada

Eric Lin
Eric Lin el 16 de Jun. de 2015
The following submissions on the MATLAB File Exchange may be of help:
plot2axes: allows you to provide a function that describes the relationship of one axes to another (ex. Celsius and Farenheit)
extendticklabel: allows you to specify the number of significant digits for tick labels
  1 comentario
Adam Goldsmith
Adam Goldsmith el 16 de Jun. de 2015
Thanks! This seems like it would work, so I'm accepting. But I solved the issue myself with a series of patches. Here's the final code:
TCtoEDDR = polyfit(log(Tc_EDDR),log(EDDR),1); % Tc and EDDR are a power law function of each other
esrTc = exp(log(esr) * EDDRtoTC(1) + EDDRtoTC(2)); % Tc assuming observed Ea and r = ESR
figure(14)
[fig14,ax1,ax2] = plotyy([min(realTC) max(realTC)],[esr esr],realTC,EDDR,@line,@line);
set(ax1,'LineWidth',1.5,'Color','k','LineStyle','--')
set(ax2,'LineWidth',1,'Color','k','LineStyle','-')
set(fig14(1),'YColor','k','LineWidth',1,'box','off')
set(fig14(2),'YColor','k','LineWidth',1)
legend('Observed equivalent spherical radius','Effectivered diffusion domain size')
title(['EDDR and T_{c} vs Temperature for ' sample_name])
xlabel('Temperature (°C)')
fig14(1).YLabel.String = 'Estimated Diffusion Domain Size (\mum)';
fig14(2).YLabel.String = 'Closure temperature (°C, \deltaT/\deltat = 10 °C/m.y.)';
set(fig14(1),'YLim',[min(EDDR)-5 max(EDDR)+5],'YTick',0:EDDRtick:600)
set(fig14(2),'YLim',[min(EDDR)-5 max(EDDR)+5])
fig14y1 = 0:TCtick:250;
fig14y2 = exp(log(fig14y1) * TCtoEDDR(1) + TCtoEDDR(2));
set(fig14(2),'YTickLabel',fig14y1,'YTick',fig14y2)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by