I have two lists. The first is a list of strings a
[\'Agriculture/Forestry/Fisheries/Veterinary Medicine\',
\'Architectural and Town Planning\',
\
list(zip(list_name, list_count))
zips the two lists into a list of tuples
dtypes
[::-1]
reverses the arraymatplotlib
easily accepts arrays, and the numpy
column can be passed with its name.import numpy as np
import matplotlib.pyplot as plt
text = ['Agriculture/Forestry/Fisheries/Veterinary Medicine', 'Architectural and Town Planning', 'Business Administration and Related']
values = [66667.0, 22283.0, 670091.5]
# get the length of the longest string in text, for the numpy str dtype
# this is only necessary if make sure the entire string is included in the array
str_len = max([len(t) for t in text])
# create numpy array with dtypes
t = np.array(list(zip(text, values)), dtype = [('text', f'S{str_len}'), ('values', int)])
# sort array
t = np.sort(t, order=['values'])[::-1]
# plot
plt.bar(x=t['text'], height=t['values'])
plt.xticks(rotation=90)