如何移除这两条灰色线(在所附图形的最右端和顶部)并保持这两条轴线?
#plt.style.use('Solarize_Light2')
plt.rcParams["figure.figsize"] = (50, 35)
plotdata = pd.DataFrame(result1)
plotdata.plot(kind="bar")
plt.legend(loc=0, prop={'size': 25})
plt.title("Actual Vs. Predicted Stratospheric Ozone Depletion", fontsize=30)
plt.xticks(rotation=0)
plt.xlabel("Index", fontsize=30)
ax.yaxis.offsetText.set_fontsize(50)
plt.ylabel("(kg CFC-11 eq.)", fontsize=30)
plt.tick_params(labelsize=30)
plt.grid(False)审判1:
plt.rcParams["figure.figsize"] = (50, 35)
plotdata = pd.DataFrame(result1)
plotdata.plot(kind="bar")
plt.legend(loc=0, prop={'size': 25})
plt.title("Actual Vs. Predicted Stratospheric Ozone Depletion", fontsize=30)
plt.xticks(rotation=0)
plt.xlabel("Index", fontsize=30)
ax.yaxis.offsetText.set_fontsize(50)
plt.ylabel("(kg CFC-11 eq.)", fontsize=30)
plt.tick_params(labelsize=30)
plt.grid(False)
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)发布于 2022-10-04 03:01:49
您可以使用set_visible命令去除部分边界。例如,请考虑以下内容。
import matplotlib.pyplot as plt
import numpy as np
# Generate the figure
###############
labels = ['G1', 'G2', 'G3', 'G4', 'G5']
men_means = [20, 34, 30, 35, 27]
women_means = [25, 32, 34, 20, 25]
x = np.arange(len(labels)) # the label locations
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, men_means, width, label='Men')
rects2 = ax.bar(x + width/2, women_means, width, label='Women')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(x, labels)
ax.legend()
# remove top/right boundary
###################
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)
######
plt.show()生成的图表:

https://stackoverflow.com/questions/73942641
复制相似问题