I am trying to plot a bar diagram using input from a .csv file.
My input file contains several columns with sample names and data and also a column with the colour of my sample. This column contains strings, such as 'w' meaning white, 'b' meaning brown and so forth. Each line contains values for a different sample.
Now I want the bar for each sample to have the colour specified in the colour column.
My code looks a bit like this:
import numpy as np
import matplotlib.pyplot as plt
results_dtype=np.dtype([('name', 'S100'), ('colour', 'S10'),
('data_this', 'float64'), ('data_that', 'float64'), ...])
data = np.genfromtxt('C:/data.csv', delimiter = ',', dtype =results_dtype, filling_values=np.nan, skip_header=1)
colours = {'w':'#FFFFFF',
'y':'#ffff00',
'b':'#cc8033',
'p':'#CC79A7'}
fig = plt.figure()
plt.bar(np.arange(len(data)), data['data_this'], bottom=data['data_that'], align='center', color=colours[data['colour']])
plt.xticks(np.arange(len(data)), data['name'], rotation='vertical')
plt.show()
The error message I get is the following:
unhashable type: 'numpy.ndarray' (pointing to the plt.bar(...) line).
It sounds like I'm calling the dictionary the wrong way or something along those lines but I can't figure out how to do it properly.
I hope, this is explains what I'm trying to do.