Add support to use markers in plot legend - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrancesco <franko@hp-gosia.(none)>2012年02月25日 11:16:20 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年02月26日 21:48:55 +0100
commitabf9a4a14366b98bb9e95f16dee54aa0b70629c3 (patch)
tree2622a06e7fdb9e0a95be44f7d6d2e240d2853d9a
parent1b9b5f323110c9fea8402cb397ce27423df9e1fd (diff)
downloadgsl-shell-marker-new.tar.gz
Add support to use markers in plot legendmarker-new
Diffstat
-rw-r--r--demos/plot.lua 3
-rw-r--r--graph-init.lua 8
2 files changed, 5 insertions, 6 deletions
diff --git a/demos/plot.lua b/demos/plot.lua
index b95e4a58..1ae6eb67 100644
--- a/demos/plot.lua
+++ b/demos/plot.lua
@@ -125,6 +125,7 @@ local function legend_demo()
local p = graph.legend {
{'sinus', 'red', 'line'},
{'cosinus', 'blue', 'line', {{'dash', 7, 3}}},
+ {'exp', 'red', 'circle'},
}
p:show()
@@ -133,9 +134,11 @@ local function legend_demo()
local mp = graph.fxplot(math.sin, 0, 2*pi, 'red', 32)
mp:addline(graph.fxline(math.cos, 0, 2*pi, 32), 'blue', {{'dash', 7,3}})
+ mp:add(graph.fxline(|x| math.exp(-x), 0, 2*pi, 32), 'red', {{'marker', size=5, mark='circle'}})
mp.title = 'Plot example'
mp.xtitle = 'x axis title'
+ mp.clip = false
mp:set_mini(p)
mp:save_svg('demo.svg', 600, 400)
p:save_svg('legend.svg', 400, 200)
diff --git a/graph-init.lua b/graph-init.lua
index 48f0f828..e233fb0f 100644
--- a/graph-init.lua
+++ b/graph-init.lua
@@ -280,14 +280,10 @@ function graph.plot_lines(ln, title)
end
local function legend_symbol(sym, dx, dy)
- if sym == 'square' then
- return graph.rect(5+dx, 5+dy, 15+dx, 15+dy)
- elseif sym == 'circle' then
- return graph.ellipse(10+dx, 10+dy, 5, 5)
- elseif sym == 'line' then
+ if sym == 'line' then
return graph.segment(2+dx, 10+dy, 18+dx, 10+dy), {'stroke'}
else
- error('invalid legend symbol: ' .. sym)
+ return graph.marker(10+dx, 10+dy, sym, 8)
end
end
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月11日 00:03:45 +0000

AltStyle によって変換されたページ (->オリジナル) /