bugGNU Octave - Bugs: bug #36014, Wrong second axes when saved in pdf

 
 

bug #36014: Wrong second axes when saved in pdf

Submitter:  Dik Dirk <dikdirk>
Submitted:  Tue 27 Mar 2012 03:12:21 PM UTC
   
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Invalid / Not an Octave Bug Assigned to:  bpabbott
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 30 Mar 2012 01:54:17 AM UTC, comment #7: 

Ok. I'm closing this report

Ben Abbott <bpabbott>
Group Member
Thu 29 Mar 2012 08:22:37 AM UTC, comment #6: 

Thank you, it is currently working in the way I want it to work. For completeness, this is the code

clf()
x1 = [0:.1:40];
y1 = 4.*cos(x1)./(x1+2);
plot(x1,y1)
ax1 = gca;
ax2=axes('Color','none','XTick',[],'YAxisLocation','right','YTick',exp(get(ax1,'YTick')),'YLim',exp(get(ax1,'YLim')),'XLim',get(ax1,'XLim'),'YScale','log');
h1=ylabel(ax1,'Log Index');
h2=ylabel(ax2,'Index');
position1 = get (ax1, "position");
position2 = get (ax2, "position");
position = [max(position1(1),position2(1))*0.95,max(position1(2),position2(2)),min(position1(3),position2(3))*0.9,min(position1(4),position2(4))];
set ([ax1, ax2], "position", position, "activepositionproperty", "position")

set(gcf,'PaperUnits','centimeters')
set(gcf,'PaperSize', [15 12])
set(gcf,'PaperPosition',[0 0 15 12])
drawnow

saveas(gcf,'test3.pdf')

Dik Dirk <dikdirk>
Wed 28 Mar 2012 12:13:42 PM UTC, comment #5: 

The outerposition is the box that encompass the plotbox, tick labels, axes labels, and the title.

The position property is just the plot box.

To align the two axis plot boxes, try


x1 = [0:.1:40];
y1 = 4.*cos(x1)./(x1+2);
plot(x1,y1)
ax1 = gca;
ax2=axes('Color','none','XTick',[],'YAxisLocation','right','YTick',exp(get(ax1,'YTick')),'YLim',exp(get(ax1,'YLim')),'XLim',exp(get(ax1,'XLim')),'YScale','log');
ylabel(ax1,'Log Index')
ylabel(ax2,'Index')
position1 = get (ax1, "position");
position2 = get (ax2, "position");
position = [max(position1(1:2),position2(1:2)), min(position1(3:4),position2(3:4))];
set ([ax1, ax2], "position", position, "activepositionproperty", "position")


If you find that the right y-axes label may gets clipped, you can decrease the value of the plotbox width, position(3).

Ben Abbott <bpabbott>
Group Member
Wed 28 Mar 2012 09:08:40 AM UTC, comment #4: 

Thanks for all the work you are doing on octave, it's a great product!
I have also tested the following code and have set properties of ax1 to the ones of ax2 (i.e. if I understand correctly adding a label to ax2 changes the position of the axis, so then we have to relocate ax1). Afterwards I checked the settings of position, outerposition and activepositionproperty for both axes... they are the same.
The output however, is not correct or I don't understand why it is correct, see test3.pdf. I hope this helps in sorting this out.

x1 = [0:.1:40];
y1 = 4.*cos(x1)./(x1+2);
plot(x1,y1)

ax1 = gca;
ax2=axes('ActivePositionProperty','outerposition','Color','none','XTick',[],'YAxisLocation','right','YTick',exp(get(ax1,'YTick')),'YLim',exp(get(ax1,'YLim')),'XLim',exp(get(ax1,'XLim')),'YScale','log');
ylabel(ax1,'Log Index')
ylabel(ax2,'Index')
set (ax1,'OuterPosition', get (ax2, 'OuterPosition'))
set (ax1,'ActivePositionProperty','outerposition')


set(gcf,'PaperUnits','centimeters')
set(gcf,'PaperSize', [15 12])
set(gcf,'PaperPosition',[0 0 15 12])

drawnow
pause(2)
saveas(gcf,'test3.pdf')

(file #25489)

Dik Dirk <dikdirk>
Wed 28 Mar 2012 08:22:12 AM UTC, comment #3: 

Unfortunately, this still doesn't work for me, your code produces the attachted pdf, see pdf test2.pdf.



(file #25487)

Dik Dirk <dikdirk>
Wed 28 Mar 2012 12:54:38 AM UTC, comment #2: 

Turns out this isn't a bug.

Since the value for the position property for ax2 never changes the updater never changes the activepositionproperty to "position".

If the ylabel for ax2 is set before "set (ax2, 'Position', get (ax1, 'Position')" then it works as intended.


clf ()

x1 = [0:.1:40];
y1 = 4.*cos(x1)./(x1+2);
plot(x1,y1)
ax1 = gca;
set (ax1, "activepositionproperty", "position");

ax2 = axes ();
set (ax2, 'OuterPosition', get (ax1, 'OuterPosition'),
          'Color', 'none',
          'XTick', [],
          'YAxisLocation', 'right',
          'YTick', exp (get (ax1, 'YTick')),
          'YLim', exp (get (ax1, 'YLim')),
          'XLim', exp (get (ax1, 'XLim')),
          'YScale', 'log');
ylabel (ax1, 'Log Index')
ylabel (ax2, 'Index')

set (ax2, 'Position', get (ax1, 'Position'))

set (gcf, 'PaperUnits', 'centimeters')
set (gcf, 'PaperSize', [15 12])
set (gcf, 'PaperPosition', [0 0 15 12])

saveas(gcf,'test.pdf')


While this behavior is a bit esoteric, I think Octave is working as it should, so I'm changing the status to invalid. I'll leave it open in case I've missed something or in case more discussion is merited.

Ben Abbott <bpabbott>
Group Member
Tue 27 Mar 2012 03:41:13 PM UTC, comment #1: 

Your example has a bug in it. The "activepositionproperty" for ax1 is "outerposition" and that for ax2 is "position".

The following fixes that


clf ()

x1 = [0:.1:40];
y1 = 4.*cos(x1)./(x1+2);
plot(x1,y1)
ax1 = gca;
set (ax1, "activepositionproperty", "position");

ax2 = axes ();
set (ax2, 'OuterPosition', get (ax1, 'OuterPosition'),
          'Position', get (ax1, 'Position'),
          'Color', 'none',
          'XTick', [],
          'YAxisLocation', 'right',
          'YTick', exp (get (ax1, 'YTick')),
          'YLim', exp (get (ax1, 'YLim')),
          'XLim', exp (get (ax1, 'XLim')),
          'YScale', 'log');
ylabel (ax1, 'Log Index')
ylabel (ax2, 'Index')

set (gcf, 'PaperUnits', 'centimeters')
set (gcf, 'PaperSize', [15 12])
set (gcf, 'PaperPosition', [0 0 15 12])

saveas(gcf,'test.pdf')


However, this still does not work. The updater for "position" should be changing the "activepositionproperty" for ax2, but is not.

I'll take a look.

For now, a work around is to add the following lines.


set (ax2, 'OuterPosition', get (ax1, 'OuterPosition'),
          'Position', get (ax1, 'Position'),
          'ActivePositionProperty', 'Position')


Ben Abbott <bpabbott>
Group Member
Tue 27 Mar 2012 03:12:21 PM UTC, original submission:  

The attached code adds an extra y-axis with a log scale on the right. However, when saved in pdf. The second axes shifts, see attatched pdf.

This bug is probably related to bug #35908, therefore I cannot test this in 3.6.1 (as explained in #35908, in 3.6.1 saving in pdf without the second axis already produces an incorrect result).


Dik Dirk <dikdirk>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #25489:  test3.pdf added by dikdirk (6KiB - application/pdf)
file #25487:  test2.pdf added by dikdirk (6KiB - application/pdf)
file #25476:  test.pdf added by dikdirk (6KiB - application/pdf)
file #25477:  bug_extra_yaxis.m added by dikdirk (480B - text/x-objective-c)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bpabbott (Posted a comment)
  • -email is unavailable- added by dikdirk (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-03-30 bpabbott Open/ClosedOpen Closed
    2012-03-28 dikdirk Attached File- Added test3.pdf, #25489
    2012-03-28 dikdirk Attached File- Added test2.pdf, #25487
    2012-03-28 bpabbott StatusNone Invalid / Not an Octave Bug
    2012-03-27 bpabbott Assigned toNone bpabbott
        Release3.4.3 dev
        Operating SystemMicrosoft Windows Any
    2012-03-27 dikdirk Attached File- Added test.pdf, #25476
        Attached File- Added bug_extra_yaxis.m, #25477

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code