[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help with minor grid
From: |
Rik |
Subject: |
Re: Help with minor grid |
Date: |
Wed, 26 Aug 2015 08:55:10 -0700 |
On 08/26/2015 05:47 AM, John W. Eaton wrote:
> On 08/25/2015 07:32 PM, Michael Godfrey wrote:
>> Atached is result of:
>>
>>
>> plot (1:10)
>> set (gca, 'xtick', [0 1 5 6 9 10])
>> grid minor
>
> Hmm, so even though you specify a tick mark at 0, it's not displayed
> because of the data range being 1:10? Is it always the case that tick
> marks outside the data range (or axes limits, I guess, which might be
> computed from the data range) are ignored? That seems like one problem
> to solve and the other is to properly handle the minor ticks when the
> major ticks are not evenly spaced.
There seems to be several problems which need to be disentangled. When the
command 'set (gca, 'xtick', ...)' is executed I notice that I do not hit a
breakpoint in calc_ticks_and_lims in graphics.cc. This means only the
'xtick' property itself is being updated, but there is no listener that is
also asking for the limits to be updated.
Secondly, in calc_ticks_and_lims, there is code that is supposed to do what
we want. See the comment "// Adjust limits to include min and max ticks".
But I don't think the line 'lims = tmp_lims' can possible be right because
lims is a graphics property object while tmp_lims is a Matrix. It seems
like 'lims.set (tmp_lims)' would be more appropriate.
--Rik
void
axes::properties::calc_ticks_and_lims (array_property& lims,
array_property& ticks,
array_property& mticks,
bool limmode_is_auto, bool is_logscale)
{
// FIXME: add log ticks and lims
if (lims.get ().is_empty ())
return;
double lo = (lims.get ().matrix_value ())(0);
double hi = (lims.get ().matrix_value ())(1);
bool is_negative = lo < 0 && hi < 0;
double tmp;
// FIXME: should this be checked for somewhere else? (i.e. set{x,y,z}lim)
if (hi < lo)
std::swap (hi, lo);
if (is_logscale)
{
if (is_negative)
{
tmp = hi;
hi = std::log10 (-lo);
lo = std::log10 (-tmp);
}
else
{
hi = std::log10 (hi);
lo = std::log10 (lo);
}
}
double tick_sep;
if (is_logscale)
{
if (! (xisinf (hi) || xisinf (lo)))
tick_sep = 1; // Tick is every order of magnitude (bug #39449)
else
tick_sep = 0;
}
else
tick_sep = calc_tick_sep (lo, hi);
int i1 = static_cast<int> (gnulib::floor (lo / tick_sep));
int i2 = static_cast<int> (std::ceil (hi / tick_sep));
if (limmode_is_auto)
{
// Adjust limits to include min and max ticks
Matrix tmp_lims (1,2);
tmp_lims(0) = std::min (tick_sep * i1, lo);
tmp_lims(1) = std::max (tick_sep * i2, hi);
if (is_logscale)
{
tmp_lims(0) = std::pow (10., tmp_lims(0));
tmp_lims(1) = std::pow (10., tmp_lims(1));
if (tmp_lims(0) <= 0)
tmp_lims(0) = std::pow (10., lo);
if (is_negative)
{
tmp = tmp_lims(0);
tmp_lims(0) = -tmp_lims(1);
tmp_lims(1) = -tmp;
}
}
lims = tmp_lims;
}
else
{
// adjust min and max ticks to be within limits
if (i1*tick_sep < lo)
i1++;
if (i2*tick_sep > hi && i2 > i1)
i2--;
}