缺少轴的matplotlib颜色栏
缺少轴的matplotlib颜色栏,matplotlib,colorbar,Matplotlib,Colorbar,我曾多次尝试绘制此图,但为什么每次都缺少X轴?色条标签、Y轴和标题是正常的,但只有X轴不起作用。您可以通过一个最小的工作示例,让您的问题更切题,在这个示例中,您使用一些虚拟问题,您只需要几行代码。What islog_返回和其他变量? for i in range(5000): weights = np.random.random(12) weights /= np.sum(weights) ER = np.sum(log_returns.
我曾多次尝试绘制此图,但为什么每次都缺少X轴?色条标签、Y轴和标题是正常的,但只有X轴不起作用。您可以通过一个最小的工作示例,让您的问题更切题,在这个示例中,您使用一些虚拟问题,您只需要几行代码。What is
log_返回
和其他变量?
for i in range(5000):
weights = np.random.random(12)
weights /= np.sum(weights)
ER = np.sum(log_returns.mean() * weights) * 252
SD = np.sqrt(np.dot(weights.T , np.dot(an_cov,weights)))
rf = 0.02
Sharpe = (ER - rf)/SD
port_return.append(ER)
port_vol.append(SD)
port_sharpe.append(Sharpe)
s_weight.append(weights)
P = {'Portfolio Expected Return':port_return, 'Portfolio Standard
Deviation':port_vol, 'Stock Weights':s_weight , 'Portfolio Sharpe
Ratio':port_sharpe}
Q = pd.DataFrame(P)
plt.style.use('seaborn')
Q.plot.scatter(x='Portfolio Standard Deviation',y='Portfolio Expected
Return',c = 'Portfolio Sharpe Ratio',figsize=(12,9), grid=True,
cmap='RdYlGn')
plt.xlabel('Volatility (Std. Deviation)')
plt.ylabel('Expected Returns')
plt.title('random portfolios')
plt.show()