I want to use a list entry consisting of appearance commands in matplotlib for convenient editing of the line color and type. But when I run the following code I get 2 errors:
- 'type object got multiple values for keyword argument 'ax''
Traceback (most recent call last):
File "./plotMeltFront.py", line 34, in <module>
data.plot(0, 1, ax=ax1, label=myLabel, *sets[i][2].split())
File "/home/ksalscheider/.local/lib/python3.6/site-packages/pandas/plotting/_core.py", line 872, in __call__
plot_backend.__name__, self._parent, args, kwargs
File "/home/ksalscheider/.local/lib/python3.6/site-packages/pandas/plotting/_core.py", line 859, in _get_call_args
kwargs = dict(arg_def, **pos_args, **kwargs)
TypeError: type object got multiple values for keyword argument 'ax'
- On deleting the ax argument the error says 'color="C0" is not a valid plot kind'
Traceback (most recent call last):
File "./plotMeltFront.py", line 34, in <module>
data.plot(0, 1, label=myLabel, *sets[i][2].split())
File "/home/ksalscheider/.local/lib/python3.6/site-packages/pandas/plotting/_core.py", line 882, in __call__
raise ValueError(f"{kind} is not a valid plot kind")
ValueError: color="C0" is not a valid plot kind
I don't understand either of them. For 1 I didn't declare a second ax value in the lists, why does it say so? Error 2 occurs too, when writing data.plot(0, 1, label=myLabel, 'color="C0"')
(watch the ' around color). This mimics the way the list entries look, wen the list is printed. Is there a way to strip the ' from the split list entries?
I included the script with a few example sets in the link python script with example data
#!/usr/bin/python3
import os
import matplotlib.pyplot as plt
import pandas as pd
sets = []
iOld = -1
#--------USER EDIT--------#
#["set directory name", "label", 'set appearence']
sets.append(["set1", "Experiment", 'color="C0" linestyle=":"'])
sets.append(["set2", "Linear", 'color="C1" linestyle="--"'])
sets.append(["set3", "Erf", 'color="C2" linestyle="-."'])
print(sets[0][2].split())
#------USER EDIT END------'
fig = plt.figure()
ax1 = fig.add_subplot()
for i in range(len(sets)):
for j in os.listdir(sets[i][0]):
filepath = os.path.abspath(sets[i][0]) + "/" + j
data = pd.read_csv(filepath, delimiter=',', engine='python',
header=None, skipfooter=1, error_bad_lines=False)
if i != iOld:
myLabel = sets[i][1];
else:
myLabel = '_nolegend_'
data.plot(0, 1, ax=ax1, label=myLabel, *sets[i][2].split())
iOld = i
plt.show()
PS: The "nolegend" entry throws a lot of warnings, is there a way to disable them?