Issues getting dual y-axis ticks/values to line up
2 views (last 30 days)
Show older comments
Adam Goldsmith
on 15 Jun 2015
Commented: Adam Goldsmith
on 16 Jun 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?

0 Comments
Accepted Answer
Eric Lin
on 16 Jun 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
More Answers (0)
See Also
Categories
Find more on Propagation and Channel Models in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!