aboutsummaryrefslogtreecommitdiffstats
path: root/examples/graphstyles
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-02-21 18:08:55 -0800
committerbnewbold <bnewbold@robocracy.org>2016-02-21 18:08:55 -0800
commitb24f282bca4af63982937c10835063d3e6e9eb74 (patch)
treefd8c58601beb3964ccecf4709f7b28944fc1c36b /examples/graphstyles
parent84572be10cdfc852530787a5dc78ddef3e0f23cd (diff)
downloadPyX.jl-b24f282bca4af63982937c10835063d3e6e9eb74.tar.gz
PyX.jl-b24f282bca4af63982937c10835063d3e6e9eb74.zip
add many, many more example conversions. still not complete
Diffstat (limited to 'examples/graphstyles')
-rw-r--r--examples/graphstyles/density.jl86
-rw-r--r--examples/graphstyles/errorbar.dat6
-rw-r--r--examples/graphstyles/errorbar.jl19
-rw-r--r--examples/graphstyles/histogram.jl29
-rw-r--r--examples/graphstyles/usesymbol.jl41
5 files changed, 181 insertions, 0 deletions
diff --git a/examples/graphstyles/density.jl b/examples/graphstyles/density.jl
new file mode 100644
index 0000000..957b487
--- /dev/null
+++ b/examples/graphstyles/density.jl
@@ -0,0 +1,86 @@
+
+# Original Python:
+# from pyx import *
+#
+# # Mandelbrot calculation contributed by Stephen Phillips
+#
+# # Mandelbrot parameters
+# re_min = -2
+# re_max = 0.5
+# im_min = -1.25
+# im_max = 1.25
+# gridx = 100
+# gridy = 100
+# max_iter = 10
+#
+# # Set-up
+# re_step = (re_max - re_min) / gridx
+# im_step = (im_max - im_min) / gridy
+# d = []
+#
+# # Compute fractal
+# for re_index in range(gridx):
+# re = re_min + re_step * (re_index + 0.5)
+# for im_index in range(gridy):
+# im = im_min + im_step * (im_index + 0.5)
+# c = complex(re, im)
+# n = 0
+# z = complex(0, 0)
+# while n < max_iter and abs(z) < 2:
+# z = (z * z) + c
+# n += 1
+# d.append([re, im, n])
+#
+# # Plot graph
+# g = graph.graphxy(height=8, width=8,
+# x=graph.axis.linear(min=re_min, max=re_max, title=r"$\Re(c)$"),
+# y=graph.axis.linear(min=im_min, max=im_max, title=r'$\Im(c)$'))
+# g.plot(graph.data.points(d, x=1, y=2, color=3, title="iterations"),
+# [graph.style.density(gradient=color.rgbgradient.Rainbow)])
+# g.writeEPSfile()
+# g.writePDFfile()
+# g.writeSVGfile()
+
+using PyX
+using LaTeXStrings
+
+# Mandelbrot parameters
+re_min = -2
+re_max = 0.5
+im_min = -1.25
+im_max = 1.25
+gridx = 100
+gridy = 100
+max_iter = 10
+
+# Set-up
+re_step = (re_max - re_min) / gridx
+im_step = (im_max - im_min) / gridy
+# Julia note: indexing is opposite of what would be idiomatic Julia
+d = zeros(gridx*gridy, 3)
+
+# Compute fractal
+for re_index in 0:(gridx-1)
+ re = re_min + re_step * (re_index + 0.5)
+ for im_index in 0:(gridy-1)
+ im = im_min + im_step * (im_index + 0.5)
+ c = complex(re, im)
+ n = 0
+ z = complex(0, 0)
+ while n < max_iter && abs(z) < 2
+ z = (z * z) + c
+ n += 1
+ end
+ d[re_index*gridy + im_index + 1, :] = [re, im, n]
+ end
+end
+
+# Plot graph
+g = graph.graphxy(height=8, width=8,
+ x=graph_axis.linear(min=re_min, max=re_max, title=L"$\Re(c)$"),
+ y=graph_axis.linear(min=im_min, max=im_max, title=L"$\Im(c)$"))
+plot(g, graph_data.points(d, x=1, y=2, color=3, title="iterations"),
+ [graph_style.density(gradient=color_rgbgradient.Rainbow)])
+writeEPSfile(g, "density")
+writePDFfile(g, "density")
+
diff --git a/examples/graphstyles/errorbar.dat b/examples/graphstyles/errorbar.dat
new file mode 100644
index 0000000..bd33a65
--- /dev/null
+++ b/examples/graphstyles/errorbar.dat
@@ -0,0 +1,6 @@
+1 2 0.7
+2 3 0.9
+3 8 0.8
+4 13 1.2
+5 18 1.1
+6 21 1.3
diff --git a/examples/graphstyles/errorbar.jl b/examples/graphstyles/errorbar.jl
new file mode 100644
index 0000000..94b80dc
--- /dev/null
+++ b/examples/graphstyles/errorbar.jl
@@ -0,0 +1,19 @@
+
+# Original Python:
+# from pyx import *
+#
+# g = graph.graphxy(width=8)
+# g.plot(graph.data.file("errorbar.dat", x=1, y=2, dy=3),
+# [graph.style.symbol(), graph.style.errorbar()])
+# g.writeEPSfile("errorbar")
+# g.writePDFfile("errorbar")
+# g.writeSVGfile("errorbar")
+
+using PyX
+
+g = graph.graphxy(width=8)
+plot(g, graph_data.file("examples/graphstyles/errorbar.dat", x=1, y=2, dy=3),
+ [graph_style.symbol(), graph_style.errorbar()])
+writeEPSfile(g, "errorbar")
+writePDFfile(g, "errorbar")
+
diff --git a/examples/graphstyles/histogram.jl b/examples/graphstyles/histogram.jl
new file mode 100644
index 0000000..ebe35c6
--- /dev/null
+++ b/examples/graphstyles/histogram.jl
@@ -0,0 +1,29 @@
+
+# Original Python:
+# from pyx import *
+#
+# d = graph.data.points([(1, 0.3),
+# (2, -0.7),
+# (3, -0.3),
+# (4, 0.8),
+# (5, 0.5)], x=1, y=2)
+#
+# g = graph.graphxy(width=8)
+# g.plot(d, [graph.style.histogram()])
+# g.writeEPSfile("histogram")
+# g.writePDFfile("histogram")
+# g.writeSVGfile("histogram")
+
+using PyX
+
+d = graph_data.points([(1, 0.3),
+ (2, -0.7),
+ (3, -0.3),
+ (4, 0.8),
+ (5, 0.5)], x=1, y=2)
+
+g = graph.graphxy(width=8)
+plot(g, d, [graph_style.histogram()])
+writeEPSfile(g, "histogram")
+writePDFfile(g, "histogram")
+
diff --git a/examples/graphstyles/usesymbol.jl b/examples/graphstyles/usesymbol.jl
new file mode 100644
index 0000000..af49f99
--- /dev/null
+++ b/examples/graphstyles/usesymbol.jl
@@ -0,0 +1,41 @@
+
+# Original Python:
+# from pyx import *
+#
+# # colors and symbols to use (alternatingly)
+# colors = [color.rgb.red, color.rgb.green, color.rgb.blue, color.gray.black]
+# symbols = [graph.style._diamondsymbol, graph.style._trianglesymbol, graph.style._circlesymbol]
+#
+# # create the graph styles to be used below
+# symbol = graph.style.symbol(symbol=attr.changelist(symbols),
+# symbolattrs=[deco.stroked.clear,
+# attr.changelist([deco.filled([cc]) for cc in colors])])
+# line = graph.style.line(lineattrs=[attr.changelist(colors),
+# attr.changelist([style.linestyle.solid])])
+#
+# g = graph.graphxy(width=8, x=graph.axis.linear(min=0, max=1))
+# g.plot([graph.data.function("y(x) = x**%d" % i, points=8) for i in range(1, 7)],
+# styles=[line, symbol])
+# g.writeEPSfile("usesymbol")
+# g.writePDFfile("usesymbol")
+# g.writeSVGfile("usesymbol")
+
+using PyX
+
+# colors and symbols to use (alternatingly)
+colors = [color_rgb.red, color_rgb.green, color_rgb.blue, color_gray.black]
+symbols = [graph_style._diamondsymbol, graph_style._trianglesymbol, graph_style._circlesymbol]
+
+# create the graph styles to be used below
+symbol = graph_style.symbol(symbol=attr.changelist(symbols),
+ symbolattrs=[deco_stroked.clear,
+ attr.changelist([deco.filled([cc]) for cc in colors])])
+line = graph_style.line(lineattrs=[attr.changelist(colors),
+ attr.changelist([style_linestyle.solid])])
+
+g = graph.graphxy(width=8, x=graph_axis.linear(min=0, max=1))
+plot(g, [graph_data_function("y(x) = x**$i", points=8) for i in 1:7],
+ styles=[line, symbol])
+writeEPSfile(g, "usesymbol")
+writePDFfile(g, "usesymbol")
+