Skip to content

Commit

Permalink
Add one more point to the end of a ListStepPlot...
Browse files Browse the repository at this point in the history
like WMA does
  • Loading branch information
rocky committed Sep 27, 2024
1 parent 1d063a8 commit 394e2e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
10 changes: 6 additions & 4 deletions mathics/builtin/drawing/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2067,14 +2067,16 @@ class ListStepPlot(_ListPlot):
>> ListStepPlot[{1, 1, 2, 3, 5, 8, 13, 21}]
= -Graphics-
By default ListStepPlots are joined, but that can be disabled.
'ListPlot' accepts a superset of the Graphics options. \
By default, 'ListStepPlot's are joined, but that can be disabled.
>> ListStepPlot[{1, 1, 2, 3, 5, 8, 13, 21}, Joined->False]
= -Graphics-
ListPlot accepts a superset of the Graphics options.
>> ListStepPlot[{{-2, -1}, {-1, -1}, {1, 3}}, Filling->Axis]
The same as the first example but using a list of point as data, \
and filling the plot to the x axis.
>> ListStepPlot[{{1, 1}, {3, 2}, {4, 5}, {5, 8}, {6, 13}, {7, 21}}, Filling->Axis]
= -Graphics-
"""

Expand Down
13 changes: 9 additions & 4 deletions mathics/eval/drawing/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,13 @@ def eval_ListPlot(
break
pass

# For step plots, we have 2n - 1 points These
# we create from the n points here.
# We insert a new point from the y coordinate
# For step plots, we have 2n points; n -1 of these
# we create from the n points by
# insert a new point from the y coordinate
# of the previous point in between each new point
# other than the first point
# other than the first point. The last plot point
# has the preview plot point y value and the average
# step value added to the last x value
if list_plot_type == ListPlotType.ListStepPlot:
step_plot_group = []
last_point = seg[0]
Expand All @@ -264,6 +266,9 @@ def eval_ListPlot(
step_plot_group.append(point)
step_plot_group.append(point)
last_point = point
last_x = last_point[0]
average = last_x + ((seg[0][0] + last_x) / 2)
step_plot_group.append((average, last_point[1]))
plot_groups[lidx][i] = step_plot_group

i += 1
Expand Down

0 comments on commit 394e2e2

Please sign in to comment.