Mar-31-2017, 12:26 AM
I have a large csv file. This file is read and a
To overcome this, i change the ind to ind[j], but ended up wit ha lot of colors. And these colors do not relate to their respective bins.
Counteris returned every predefined amount of lines. As an Example:
counter = [Counter({(0, 1): 9, (1, 2): 8}), Counter({(1, 2): 99, (0, 1): 99}), Counter({(1, 2): 256, (0, 1): 189}), Counter({(1, 5): 473, (0, 1): 301})]This is the script i used.
import matplotlib.pyplot as plt import numpy from collections import Counter counter = [Counter({(0, 1): 9, (1, 2): 8}), Counter({(1, 2): 99, (0, 1): 99}), Counter({(1, 2): 256, (0, 1): 189}), Counter({(1, 5): 473, (0, 1): 301})] fig = plt.figure() ax1 = fig.add_subplot(111) N = len(counter) ind = numpy.arange(N) j = 0 while j in range(0, len(counter)): a, i = 0, 0 frequencies = counter[j].values() names = counter[j].keys() while i in range(0, len(frequencies)): if i == 0: ax1.bar(ind, frequencies[i], label=names[i], width=0.25) a = frequencies[i] else: ax1.bar(ind, frequencies[i], label=names[i], width=0.25, bottom=a) a += frequencies[i] i += 1 j += 1 labels = ["%s to %s" % (200, 202)] ax1.set_xticks(numpy.arange(N)) ax1.set_xticklabels(labels) ax1.set_ylabel("Frequency") ax1.set_xlabel("Material Contact") ax1.legend() plt. show()However, it returns as error message:
Quote:ValueError: incompatible sizes: argument 'height' must be length 4 or scalar
To overcome this, i change the ind to ind[j], but ended up wit ha lot of colors. And these colors do not relate to their respective bins.