Reputation: 1
I followed someone's tip here on how to plot a dataframe with both custom markers AND error bars. However, I don't know how to change the colors of each line in the plot.
I've tried using passing "style" and "color" but it doesn't let me specify both.
tumor = pd.DataFrame({
'Time': [0, 5, 10, 15, 20, 25],
'Capomulin': [45.0, 44.26608641544399, 43.08429058188399, 42.06431734681251, 40.71632532212173, 39.93952782686818],
'Infubinol': [45.0, 47.062001033088, 49.40390857087143, 51.29639655633334, 53.19769093422999, 55.71525236228889],
'Ketapril': [45.0, 47.38917452114348, 49.582268974622714, 52.39997374321578, 54.92093473734737, 57.678981717731574],
'Placebo': [45.0, 47.125589188437495, 49.42332947868749, 51.35974169802999, 54.36441702681052, 57.48257374394706]})
df.set_index('Time', inplace=True)
tsem = pd.DataFrame({
'Time': [0, 5, 10, 15, 20, 25],
'Capomulin': [0.0, 0.44859285020103756, 0.7026843745238932, 0.8386172472985688, 0.9097306924832056, 0.8816421535181787],
'Infubinol': [0.0, 0.23510230430767506, 0.2823459146215716, 0.35770500497539054, 0.4762095134790833, 0.5503145721542003],
'Ketapril': [0.0, 0.26481852016728674, 0.35742125637213723, 0.5802679659678779, 0.7264838239834724, 0.7554127528910378],
'Placebo': [0.0, 0.21809078325219497, 0.40206380730509245, 0.6144614435805993, 0.8396091719248746, 1.0348719877946384]})
errors.set_index('Time', inplace=True)
ax = tumor.plot(linewidth = .5, yerr = tsem, legend = False)
ax.set_prop_cycle(None)
tumor.plot(linewidth = .5,
style =["o-", "^-", "s-", "d-"],
color = ["r", "b", "g", "k"], ax = ax)
plt.grid()
plt.xlabel("Time (Days)")
plt.ylabel("Tumor Volume (mm3)")
plt.show()
I expect to get a multiline graph with the specified colors, markers, and errorbars.
However, I get this error:
ValueError: Cannot pass 'style' string with a color symbol and 'color' keyword argument. Please use one or the other or pass 'style' without a color symbol
The resulting graph only shows the error bars and lines but no markers.
Upvotes: 0
Views: 332
Reputation: 10890
Try
style =["ro-", "b^-", "gs-", "kd-"]
The reason for either style or color is, that style strings (can) contain color information, too.
Note that you should replace df
by tumor
and error
by tsem
to let the plots be created over time.
Upvotes: 1