alexh
October 2, 2023, 11:00pm
1
I put up a pull request to the racket plot package to allow controlling the margin left around a plot picture. The motivation for this is that, when using thicker lines for the drawing, the end caps for these lines are cut off at the plot margin and the lines extend past he legend bounding box.
Here is an example with the lines at extreme widths, to make the effect obvious, the problem exists at thinner widths:
The PR adds two new parameters to control the space around the plot and correct this problem:
I'm posting this here, since not many people monitor the plot repository, and I would like some feedback from the community on this PR, including if there is a better approach to fixing this problem. Here is the PR:
racket:master
← alex-hhh:ah/inset-and-padding
opened 12:56PM - 04 Jul 23 UTC
This PR introduces two new plot parameters, `plot-inset` and `plot-legend-paddin… g`, which control the amount of space left unused around the plot edge and plot legend. The motivation for this is using wider lines for the plot elements, these wider lines have an "end cap" which extends past the last pixel coordinate for the line, but, since the plot package attempts to maximize the plot area, it attempts to draw things like the axis ticks al the way to the edge.
Here is an example of the problem. When using very thick lines, the top and right edge of the plot appears to be cut off, and the sample lines in the legend extend over the legend border -- the effect is present for thinner lines as well, but it is less noticeable, this example uses an extremely thick line to make the issue more apparent.
```racket
(parameterize ([plot-line-width 20]
[line-width 20])
(plot
(list
(function sin -5 5 #:color 0 #:label "sin(x)")
(function cos -5 5 #:color 1 #:label "cos(x)"))))
```
![pr124-no-padding](https://github.com/racket/plot/assets/11592690/1ec1ae6d-4014-4280-9b19-ac83c2063b2f)
The `plot-inset` and `plot-legend-padding` parameters allow the user to control the "empty" space, allowing for the line end caps to be drawn on the plot:
```racket
(parameterize ([plot-line-width 20]
[line-width 20]
[plot-inset 11]
[plot-legend-padding 11])
(plot
(list
(function sin -5 5 #:color 0 #:label "sin(x)")
(function cos -5 5 #:color 1 #:label "cos(x)"))))
```
![pr124-with-padding](https://github.com/racket/plot/assets/11592690/b4c283db-017b-40c4-a7ab-bb1620885df8)
NOTE: I considered updating the plot layout calculations to automatically add space for the line end caps, however this would be a backwards incompatible change, as it would change plot layouts in existing plot programs that people already have.
Thanks,
Alex.