Closed x1-foundation closed 3 months ago
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
# Sample data
data = {
'Time Signature': [4, 3, 4, 4, 4],
'Key': [0, 1, 2, 3, 4],
'Mode': [1, 0, 1, 1, 0]
}
data = pd.DataFrame(data)
plt.figure(figsize=(15, 4))
plt.subplot(1, 3, 1)
sns.countplot(data['Time Signature'])
plt.xlabel('Beats per bar')
plt.ylabel('Num Songs')
plt.title('Time Signature')
plt.subplot(1, 3, 2)
axes = sns.countplot(data['Key'])
key_labels = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
axes.set_xticks(range(len(key_labels)))
axes.set_xticklabels(key_labels)
plt.ylabel('Num Songs')
plt.title('Key')
plt.subplot(1, 3, 3)
axes = sns.countplot(data['Mode'])
mode_labels = ['minor', 'major']
unique_modes = sorted(data['Mode'].unique())
axes.set_xticks(range(len(unique_modes)))
axes.set_xticklabels([mode_labels[m] for m in unique_modes])
plt.ylabel('Num Songs')
plt.title('Major vs Minor Key')
plt.tight_layout(w_pad=2)
plt.show()
Stuck here
Ahha! A Python issue rather than a JavaScript issue. I haven't used the notebook in a long time, but eventually I'm sure I will, and then I'll revisit this.
Fixed. Seaborn changed. Had to update the code to something like
seaborn.countplot(data, x='Key', hue='Key', palette='husl', legend=False)
pyplot.xticks(ticks=pyplot.xticks()[0], labels=['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'])
ValueError Traceback (most recent call last) Cell In[32], line 11 9 pyplot.subplot(1, 3, 2) 10 axes = seaborn.countplot(data['Key']) ---> 11 axes.set(xticklabels=['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']) 12 pyplot.ylabel('Num Songs') 13 pyplot.title('Key')
File /srv/conda/envs/notebook/lib/python3.10/site-packages/matplotlib/artist.py:147, in Artist.__init_subclass..(self, kwargs)
139 if not hasattr(cls.set, '_autogenerated_signature'):
140 # Don't overwrite cls.set if the subclass or one of its parents
141 # has defined a set method set itself.
142 # If there was no explicit definition, cls.set is inherited from
143 # the hierarchy of auto-generated set methods, which hold the
144 # flag _autogenerated_signature.
145 return
--> 147 cls.set = lambda self, kwargs: Artist.set(self, **kwargs)
148 cls.set. name = "set"
149 cls.set.qualname = f"{cls.qualname__}.set"
File /srv/conda/envs/notebook/lib/python3.10/site-packages/matplotlib/artist.py:1231, in Artist.set(self, kwargs) 1227 def set(self, kwargs): 1228 # docstring and signature are auto-generated via 1229 # Artist._update_set_signature_and_docstring() at the end of the 1230 # module. -> 1231 return self._internal_update(cbook.normalize_kwargs(kwargs, self))
File /srv/conda/envs/notebook/lib/python3.10/site-packages/matplotlib/artist.py:1223, in Artist._internal_update(self, kwargs) 1216 def _internal_update(self, kwargs): 1217 """ 1218 Update artist properties without prenormalizing them, but generating 1219 errors as if calling
set
. 1220 1221 The lack of prenormalization is to maintain backcompatibility. 1222 """ -> 1223 return self._update_props( 1224 kwargs, "{cls.name}.set() got an unexpected keyword argument " 1225 "{prop_name!r}")File /srv/conda/envs/notebook/lib/python3.10/site-packages/matplotlib/artist.py:1199, in Artist._update_props(self, props, errfmt) 1196 if not callable(func): 1197 raise AttributeError( 1198 errfmt.format(cls=type(self), prop_name=k)) -> 1199 ret.append(func(v)) 1200 if ret: 1201 self.pchanged()
File /srv/conda/envs/notebook/lib/python3.10/site-packages/matplotlib/axes/_base.py:74, in _axis_method_wrapper.__set_name__..wrapper(self, *args, kwargs)
73 def wrapper(self, *args, *kwargs):
---> 74 return get_method(self)(args, kwargs)
File /srv/conda/envs/notebook/lib/python3.10/site-packages/matplotlib/_api/deprecation.py:297, in rename_parameter..wrapper(*args, *kwargs)
292 warn_deprecated(
293 since, message=f"The {old!r} parameter of {func.name}() "
294 f"has been renamed {new!r} since Matplotlib {since}; support "
295 f"for the old name will be dropped %(removal)s.")
296 kwargs[new] = kwargs.pop(old)
--> 297 return func(args, **kwargs)
File /srv/conda/envs/notebook/lib/python3.10/site-packages/matplotlib/axis.py:1969, in Axis.set_ticklabels(self, labels, minor, fontdict, **kwargs) 1965 if isinstance(locator, mticker.FixedLocator): 1966 # Passing [] as a list of labels is often used as a way to 1967 # remove all tick labels, so only error for > 0 labels 1968 if len(locator.locs) != len(labels) and len(labels) != 0: -> 1969 raise ValueError( 1970 "The number of FixedLocator locations" 1971 f" ({len(locator.locs)}), usually from a call to" 1972 " set_ticks, does not match" 1973 f" the number of labels ({len(labels)}).") 1974 tickd = {loc: lab for loc, lab in zip(locator.locs, labels)} 1975 func = functools.partial(self._format_with_dict, tickd)
ValueError: The number of FixedLocator locations (1), usually from a call to set_ticks, does not match the number of labels (12).