1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import nixio
import matplotlib.pyplot as plt
import docutils
def create_data():
categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
temperatures = [100, 110, 95, 150, 200, 250]
return temperatures, categories
def store(nixfile, data, categories):
b = nixfile.create_block("test", "nix.session")
data_array = b.create_data_array("category data", "nix.categorical", data=data, label="temperature", unit="K")
data_array.append_set_dimension(categories)
return data_array
def plot(data_array):
plt.bar(range(data_array.shape[0]), data_array[:], color="tab:blue")
plt.xticks(range(data_array.shape[0]), labels=data_array.dimensions[0].labels)
plt.ylabel("%s %s" % (data_array.label, "[%s]" % data_array.unit if data_array.unit else ""))
if docutils.is_running_under_pytest():
plt.close()
else:
plt.show()
def main():
data, categories = create_data()
nixfile = nixio.File.open("categoryData.nix", nixio.FileMode.Overwrite)
data_array = store(nixfile, data, categories)
plot(data_array)
nixfile.close()
if __name__ == "__main__":
main()
|