Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
904 views
in Technique[技术] by (71.8m points)

grid - Getting rid of lines/axis in Matplotlib

How can I get rid of the last two lines (horizontal, vertical) in the chart. I tried all kind off different methods as below, but those two keep there. Can anyone point me in the direction where my code is flawed.

The ca.plot coordinates is a method called by Prince for plotting the results of a CA as matplotlib.

ax = ca.plot_coordinates(
X=X,
ax=None,
marker = "o",
color='k',
figsize=(32, 18),
x_component=0,
y_component=1,show_row_labels=False,show_col_labels=False,
)
ax.set_axis_off()
ax.get_figure().gca().set_title("")
ax.grid(False)

ax.get_legend().remove()
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.set_xticks([])
ax.set_yticks([])

ax.get_figure ()

Result


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I don't know this library, but my quick analysis of the code shows that these lines are hard-coded:

ca.plot_coordinates() calls plot.stylize_axis(), which in turns draws these two lines whether you want them or not (L21–22):

ax.axhline(y=0, linestyle='-', linewidth=1.2, color=GRAY['dark'], alpha=0.6)
ax.axvline(x=0, linestyle='-', linewidth=1.2, color=GRAY['dark'], alpha=0.6)

Thankfully, the artists thus created should be stored in ax.lines, so you should be able to remove the first two lines there:

del ax.lines[:2]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...