diff --git a/CMake/CMakeLists.txt b/CMake/CMakeLists.txt index 81159f60..95e916f0 100644 --- a/CMake/CMakeLists.txt +++ b/CMake/CMakeLists.txt @@ -3,9 +3,9 @@ cmake_minimum_required (VERSION 2.8) project(histogram) list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}) -option(USE_PYTHON ON) -option(USE_NUMPY ON) -option(BUILD_CHECKS OFF) +option(USE_PYTHON "Build Python bindings" ON) +option(USE_NUMPY "Build Numpy support" ON) +option(BUILD_CHECKS "Build auxillary checks" OFF) if(${CMAKE_BUILD_TYPE}) STRING(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE) diff --git a/examples/example_1d.py b/examples/example_1d.py new file mode 100644 index 00000000..38ec73e6 --- /dev/null +++ b/examples/example_1d.py @@ -0,0 +1,18 @@ +import histogram as hg +import numpy as np +import matplotlib.pyplot as plt + +h = hg.histogram(hg.regular_axis(10, -3, 3)) +h.fill(np.random.randn(1000)) + +bins = h.axis(0).bins + +x = np.array(h.axis(0)) # axis instances behave like sequences +y = np.asarray(h) # creates a view (no copy involved) +y = y[:bins] # cut off underflow/overflow bins +y = np.append(y, [0]) # append a zero because matplotlib's plot(...) is weird + +plt.plot(x, y, drawstyle="steps-post") +plt.xlabel("x") +plt.ylabel("y") +plt.show() diff --git a/examples/example_2d.py b/examples/example_2d.py new file mode 100644 index 00000000..b2e98e1b --- /dev/null +++ b/examples/example_2d.py @@ -0,0 +1,20 @@ +import histogram as hg +import numpy as np +import matplotlib.pyplot as plt + +h = hg.histogram(hg.regular_axis(10, -3, 3, uoflow=False), + hg.regular_axis(10, -3, 3, uoflow=False)) +xy = np.random.randn(2000).reshape((1000, 2)) +xy[:,1] *= 0.5 +h.fill(xy) + +bins = h.axis(0).bins + +x = np.array(h.axis(0)) # axis instances behave like sequences +y = np.array(h.axis(1)) +z = np.asarray(h) # creates a view (no copy involved) + +plt.pcolor(x, y, z.T) +plt.xlabel("x") +plt.ylabel("y") +plt.show()