Filter löschen
Filter löschen

How do I make two axes on the same plot using a single set of data?

2 Ansichten (letzte 30 Tage)
Nathaniel Werner
Nathaniel Werner am 7 Apr. 2017
Hello, I am trying to plot a curve with one shared y axis and two separate x axes. I am able to do this but I run into some problems.
  • First, after I run the code I wrote the data set seems to be smaller and doesn't line up correctly with either of the x axis grid points.
  • Second, the label of the top x axis is hidden and I don't know how to make the plot fit both nicely without stretching the plot window.
Here is my sample code.
figure
plot(x1,y1)
ax1 = gca;
ax1.XLabel.String = 'X-Label 1';
ax2 = axes('Position',get(ax1,'Position'),...
'XAxisLocation','top');
plot(ax2,x2,y1)
ax2.XAxisLocation = 'top;
ax2.XLabel,String = 'X-Label 2';
ylabel('Y-Label 1')
title('TITLE')
grid on
I would also like to make the grid be lined up with ax1 if possible instead of ax2.

Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by