mirror of
https://github.com/boostorg/histogram.git
synced 2025-05-09 23:04:07 +00:00
adding examples, bug-fix in cmake
This commit is contained in:
parent
611adc92b8
commit
916e687376
@ -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)
|
||||
|
18
examples/example_1d.py
Normal file
18
examples/example_1d.py
Normal file
@ -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()
|
20
examples/example_2d.py
Normal file
20
examples/example_2d.py
Normal file
@ -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()
|
Loading…
x
Reference in New Issue
Block a user