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