Bitte seien Sie nicht zu hart. Könnte mir jemand erklären, warum die Farben der Balken in diesen beiden Plots so unterschiedlich sind?Breite der Balkenplotbreite
import numpy as np
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams.update({'figure.autolayout': True})
plt.style.use('ggplot')
def plot3():
bal=np.cumsum(ret)
ind = np.arange(len(ret))
fig, ax = plt.subplots()
barlist=ax.bar(ind,ret,label="Return")
ax.plot(ind,bal,color='b',label="Balance")
for i in ind:
if ret[i]>=0:
barlist[i].set_color('g')
else:
barlist[i].set_color('r')
ax.legend(loc='best',frameon=False)
plt.show()
def plot3b():
bal=np.cumsum(ret)
ind = np.arange(len(ret))
fig, ax = plt.subplots()
colors=['g' if r>=0 else 'r' for r in ret]
ax.bar(ind,ret,color=colors,label="Return")
ax.plot(ind,bal,color='b',label="balance")
ax.legend(loc='best',frameon=False)
plt.show()
In meinem Laptop gegeben
n=100
ret=np.random.randn(n)
ret=np.insert(ret,0,0)
die Plots sind jeweils
und