Python数据可视化7-透明度设置

设置坐标刻度透明度

import matplotlib.pyplot as plt
import numpy as np
# 设置数据
x = np.linspace(-3, 3, 50)
y = 0.1*x
# 绘图
plt.figure()
plt.plot(x, y, linewidth=10, zorder=1)      # set zorder for ordering the plot in plt 2.0.2 or higher
plt.ylim(-2, 2)
# 坐标轴调整
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data', 0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data', 0))

# 设置所有坐标轴lable
for label in ax.get_xticklabels() + ax.get_yticklabels():
    label.set_fontsize(12)
    # bbox设置目的内容的透明度相关参
    # facecolor调节 box 前景色,edgecolor 设置边框,alpha设置透明度
    label.set_bbox(dict(facecolor='white', edgecolor='black', alpha=0.8, zorder=2))
plt.show()

这里写图片描述

猜你喜欢

转载自blog.csdn.net/ohcezzz/article/details/80679304