I would like to be able to better control the ticks and subticks on the axes in a graph, similar to how I can do things in tikz. I am trying to create a number line (by hiding the y-axis). My xmin and xmax dynamically scale based on the problem (so sometimes its [-15,15], other times it is [-4,4].
I would really like to be able to have ticks at integers only (of multiples of pi for other applications), but I can’t seem to find a way to control that. I know about xTickScaleFactor and <subsetOfReals>, but neither of those do exactly what I want.
I was just saying in this other thread Should labels be masked by default or always? - #4 by Duane_Nykamp1 about the border around labels that I’ve been doing this very thing frequently!
What I do is turn displayXAxisTicks="false" and displayYAxisTicks="false", then create my own ticks and labels for the values I want using <repeatForSequence>, like in the graph below.
<graph xMin="-2.5" xMax="20.5" yMin="-1" yMax="10.5" fixAxes displayXAxisTicks="false" displayYAxisTicks="false" yLabelAlignment="right" aspectRatio="1.2/1">
<shortDescription>graph of the functions I and V</shortDescription>
<xLabel><m>t</m></xLabel>
<yLabel>Value in dollars</yLabel>
<repeatForSequence from="2" to="20" step="2" valueName="k">
<lineSegment styleNumber="5" lineWidth="1" fixed endpoints="($k,-.1) ($k,.1)"/>
<label anchor="($k,-.3)" fixed><m>$k</m></label>
</repeatForSequence>
<repeatForSequence from="1" to="10" valueName="k">
<lineSegment styleNumber="5" lineWidth="1" fixed endpoints="(-.15,$k) (.15,$k)"/>
<label anchor="(-1.4,$k)" fixed><math simplify>$k*10000</math></label>
</repeatForSequence>
<function domain="[0,21]">2*1.08^x</function>
<function domain="[0,21]" styleNumber="2">2* 0.88^x</function>
<label anchor="(17,8.2)" fixed><m>I(t)</m></label>
<label anchor="(17,0.7)" fixed><m>V(t)</m></label>
</graph>
That would work, but it feels like a lot of effort. I tried looking into the JSX graph documentation and it seems like the sub ticks are generated as some % of the total width? But it also seems like there could be more features that we could control?
I haven’t tried anything with ticks lately, but in the past I found getting tick placement to work decent quite a challenge. I hacked jxsgraph ticks a little bit to improve minor ticks when major tick interval is 2 or similar, but that’s about it.
For me, the hard part about ticks is getting them to always look decent as one pans and zooms the graph.
However, we just the author choose the dx for major and minor ticks, then I could delegate all the hard work to the author!
What attributes would you want to see for axis control and how would they behave?
I’d be happy with just dx for the major and minor ticks. I would accept responsibility if it ends up looking bad. I would use it in cases where I have already determined what I want the bounds on the graph to be, so likely I’ve already used fixAxes so there is no worry about zooming in and out..
I created an issue to request these controls for the axes.
2 Likes