Add raw-lines that doesn't subdivide when a non-identity axis transform is used#110
Add raw-lines that doesn't subdivide when a non-identity axis transform is used#110tewk wants to merge 1 commit intoracket:masterfrom
Conversation
|
Can you explain what the problem is with using Perhaps provide a small example plot illustrating the problem with Thanks, Alex. |
Racket (unexpected behavior)#lang racket/base
(require plot)
(define x (list 5 203 ) )
(define y (list 1.24 510 ) )
(parameterize ( [plot-x-label #f]
[plot-y-label #f]
[plot-x-transform log-transform]
[plot-y-transform log-transform]
)
(plot (lines(map vector x y ) ) )
)Matlab (expected behavior)x = [ 5 203 ]
y = [1.24 510]
loglog( x, y )
ax = gca;
axis([x y])
xlabel("x")
ylabel("y")
ax.XGrid = "on";
ax.YGrid = "on"; |
|
Another example: Racket (unexpected behavior)#lang racket/base
(require plot)
(define x (list 28 0.13 0.006765 ) )
(define y (list 1.27 0.63 0.325 ) )
(parameterize ( [plot-x-label #f]
[plot-y-label #f]
[plot-x-transform log-transform]
[plot-y-transform log-transform]
)
(plot (lines(map vector x y ) ) )
)Matlab (expected behavior)x = [28 0.13 0.006765]
y = [1.27 0.63 0.325]
loglog( x, y, Marker="o" ) |
|
@GregVernon , thanks for providing the examples. You labelled the Racket plots as "unexpected behavior", but I don't understand why? With my limited math knowledge, a line between two points will show up as a curve on a log-log plot. If you want a straight line on a log-log plot, you need to plot a power function (see example code below). I'm not familiar with Matlab or what log-log plots are used for, can you explain what does a straight line between two points on a log-log plot represent in Matlab? I tried looking up the Given that Matlab has this behavior, I think the Racket plot package should provide it as well; but I want to make sure it is implemented appropriately -- the #lang racket
(require plot)
(define x (list 5 203 ) )
(define y (list 1.24 510 ) )
(define x0 (log 5))
(define x1 (log 203))
(define y0 (log 1.24))
(define y1 (log 510))
(define k (/ (- y1 y0) (- x1 x0)))
(define a (- y0 (* x0 k)))
(parameterize ([plot-x-label #f]
[plot-y-label #f]
[plot-x-transform log-transform]
[plot-y-transform log-transform])
(plot
(list
(tick-grid)
(function (lambda (x) (* (exp a) (expt x k))) 5 203 #:color 2)
(lines (map vector x y) #:color 1)))) |
Log plots of discrete data have their lineage from the days of graphing data by hand and wanting to identify rates of change graphically. As shown in the example below, the engineer/scientist would plot the discrete points onto graphing paper with appropriate log-axes and then use a ruler to either "connect the dots" or to "least square eyeball-norm" fit the data to a straight line. Then you could simply measure "rise over run" and it would tell you the slope: Another example, showing convergence rates for two numerical methods. Note that the author has included "guidelines" that assist with showing the rates at which the lines are converging. With a curved log-plot this can't be easily done. Another good link if you want to read more: https://www.physics.brocku.ca/PPLATO/interactive-mathematics/loglog2.html |
|
The documentation of
So if we think of a log-transform as a way of describing the paper we draw on, The matlab documentation:
And that's what happen in the example: |
|
Hi @GregVernon and @soegaard, thanks for the clarification. I was not aware of these paper-based techniques for log-log plots, but if Matlab supports them and users are familiar with them, they should be added to the plot package. I think however that |
... can be used to draw straight lines on a log-log plot, see scribble documentation for full details. See also racket#110.
|
@soegaard , I had the same concerns about the other types of axis transforms, this is why I asked for so many clarifications. However, it seems to me that those who are familiar with Matlab would expect a plot where only individual points are transformed, and the lines between points are drawn straight. In any case, I implemented an approach in #111 where the |
... can be used to draw straight lines on a log-log plot, see scribble documentation for full details. See also #110.








log-log convergence plots need to create raw-lines that aren't sampled with subdivide-lines.