问题描述
我想在直方图的y轴的右侧添加标题“ Magnitude”。还想在框架内添加散点图标题。怎么做?我可以单线添加这些功能吗?
我的代码和输出图如下所示
# definitions for the axes
left,width = 0.1,0.65 #width : width of the main plot(Xaxis length)
bottom,height = 0.1,0.4 #height : height of the main plot(Yaxis length)
spacing = 0.010 # gap between the plots
rect_scatter = [left,bottom,width,height]
rect_histx = [left,bottom + height + spacing,0.2]
rect_histy = [left + width + spacing,0.2,height]
# start with a square Figure
fig = plt.figure(figsize=(8,10))
ax = fig.add_axes(rect_scatter)
ax_histx = fig.add_axes(rect_histx,sharex=ax)
ax_histy = fig.add_axes(rect_histy,sharey=ax)
# use the previously defined function
scatter_hist(df.YearDeci,df.Magnitude,ax,ax_histx,ax_histy,binx,biny)
ax.set_xticks(np.arange(t1,t2,5))
extraticks=[2018]
ax.set_xticks(list(ax.get_xticks()) + extraticks)
plt.show()
#######################################################
def scatter_hist(x,y,biny):
# no labels
ax_histx.tick_params(axis="x",labelbottom=False)
ax_histx.set(ylabel='Number of events',title='Time',facecolor='lightgray')
ax_histy.tick_params(axis="y",labelleft=False)
ax_histy.set(xlabel='Number of events',facecolor='lightgray')
ax_histy.yaxis.set_label_position("right")
# the scatter plot:
ax.scatter(x,facecolor='yellow',alpha=0.75,edgecolor='black',linewidth=0.5,s=30)
plt.setp(ax.get_xticklabels(),rotation = 90,fontsize=10)
ax.set(xlabel='Time',ylabel='Number of events',facecolor='lightgray')
# now determine nice limits by hand:
ax_histx.hist(x,bins=binx,density=False,facecolor='r',linewidth=0.5)
ax_histy.hist(y,bins=biny,orientation='horizontal')
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)