kakearney / plotboxpos-pkg

Return the position of the plotted region of a Matlab axis
MIT License
8 stars 1 forks source link

set() functionality for plotboxpos #1

Open piermorel opened 7 years ago

piermorel commented 7 years ago

Hi Kelly,

I'm using plotboxpos as a part of my gramm dataviz toolbox (inspired by R's ggplot2 if you haven't heard about it), and it was very helpful in some cases. One thing I'm wondering about is whether you think there would be a way to set axes positions using correct coordinates, the same way plotboxpos() allows get correct coordinates. Any ideas?

Best,

Pierre

kakearney commented 7 years ago

Pierre,

Can you clarify the use case for this? In general, you can position a new axis wherever you wish:

pos = [0.1 0.1 00.5 0.4];
h = axes('position', pos);

Even with a constrained aspect ratio, the easiest way to get a desired axis box size is to simply set the axis position to match the desired plot box position.

There's an infinite number of axis position/data aspect ratio/plot box aspect ratio combos that could lead to a given plot box position. So to do an automatic calculation, you'd need at least two of these properties, plus some constraints (e.g. maximum height of axis). Is that the sort of use case you're looking for?

piermorel commented 7 years ago

Hi, thank you for the answer,

The use case is pretty specific:

I coded some dynamic adjustments on subplot axes positions when figures generated by my toolbox are resized (take a look here to see end results). This is to compensate spacing getting weird during resizing, even when functions like subtightplot are used for more control.

It works pretty well when plot box and data aspect ratios are automatic, but leaves to be desired when it's not the case. The incorrect 'Position' returned in those cases is in part to blame, which your function allows to mitigate. However, the dimensions I get from plotboxpos can not be used to set modified axes positions in a straightforward manner. The simplest example is calling set(gca,'Position',plotboxpos(gca)) several times while resizing the window in-between: the axis size gets stuck at its smallest size when making the figure larger, which is not the case if you use set(gca,'Position',get(gca,'Position')). I was wondering if you had any insight on that. I'll look at different ways to do things as well: I see that your function works in pixels units internally, maybe that's something that would make my life easier.