如何更改seaborn联合图上的刻度标签

时间:2018-03-13 21:25:35

标签: matplotlib python-3.6 seaborn data-science

我正在尝试更改其中一个边距图的seaborn关节图上的刻度标签。我正在尝试使用axes.set_xtick()axes.set_ticklabels(),但我所做的更改未能显示。

def graph_minus_Ovstretch(df1,df2):
g=sns.jointplot(x = 'opening',y = 'stretch', data = GA_All_df, space =       0.3,ratio = 3)
g.ax_joint.cla()
g.ax_marg_x.cla()
g.ax_marg_y.cla()

for xlabel_i in g.ax_marg_x.get_xticklabels():
    xlabel_i.set_visible(False)
for ylabel_i in g.ax_marg_y.get_yticklabels():
    ylabel_i.set_visible(False)

x_labels = g.ax_joint.get_xticklabels()
x_labels[0].set_visible(False)
x_labels[-1].set_visible(False)

y_labels = g.ax_joint.get_yticklabels()
y_labels[0].set_visible(False)
y_labels[-1].set_visible(False)

g.ax_joint.set_xlim(-210,210)

g.ax_marg_x.set_xlim(-210,210)
g.ax_marg_x.set_xticks(np.arange(-240,300,60))

g.ax_joint.set_xticks(np.arange(-240, 300, 60))
g.ax_joint.set_yticks(np.arange(-12, 24, 3))

g.ax_marg_y.set_yticks(np.arange(-12, 24, 3))

#plots the scatter for all pairs
if(df1['dssr'].count() != 0):
    g.ax_joint.scatter(x = df1['opening'],y = df1['stretch'],data = df1,c = 'y',edgecolors= '#080808',zorder = 2)
g.ax_joint.scatter(x = df2['opening'],y = df2['stretch'],data = df2, c= 'c',edgecolors= '#080808')

ch = chr(197)
g.ax_joint.set_ylabel('Stretch (' + ch +')')
g.ax_joint.set_xlabel('Opening (deg)')

labels = [df1.name, 'other']

g.ax_joint.legend(labels,bbox_to_anchor=(1.4, 1.25))

ax1 =g.ax_marg_x.get_axes()
ax2 = g.ax_marg_y.get_axes()
ax1.set_yscale('log')
ax2.set_xscale('log')

ax2.set_xlim(1e0, 1e4)
ax1.set_ylim(1e0, 1e3)
ax2.xaxis.set_ticks([1e0,1e1,1e2,1e3])
ax2.xaxis.set_ticklabels(("1","10","100","1000"), visible = True)

x_labels = ax2.get_xticks()

x_m_labels = ax2.get_xticklabels()

绘制边距直方图

colors = ['y','c']
ax1.hist([df1['opening'],GA_minus['opening']],bins = 20, stacked=True,log = True,color = colors, ec='black')

ax2.hist([df1['stretch'],GA_minus['stretch']],bins = 23,orientation = 'horizontal', stacked=True,log = True,color = colors, ec='black')
ax2.set_ylabel('')
g.savefig('G_minus_opening_stretch_'+df1.name)

以下是结果图的链接:

enter image description here

任何想法都会受到赞赏。

0 个答案:

没有答案