当前位置:   article > 正文

plt绘图—取消坐标轴,边框处理,白边处理,颜色图谱_plt去掉边框

plt去掉边框

调整图片像素或大小

plt.figure(dpi= 150)
plt.figure(figsize=(16,4))
  • 1
  • 2

取消坐标轴

ax = plt.subplot()
ax.contourf(grid_x_plot, grid_y_plot, f_plot, levels = levels, cmap=cmap2)
ax.set_xticks([])
ax.set_yticks([])
  • 1
  • 2
  • 3
  • 4

不显示图片边框

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
  • 1
  • 2
  • 3
  • 4

去掉图片周边白边

plt.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0)
plt.margins(0, 0)
  • 1
  • 2

生成自定义颜色谱

import matplotlib.colors as col
color1 = '#CEFFCE'
color2 = '#C7E9C0'
color3 = '#74C476'
color4 = '#238B45'
color5 = '#00441B'
cmap2 = col.LinearSegmentedColormap.from_list('own2', [color1, color2, color3, color4, color5])
 ax.contourf(grid_x_plot, grid_y_plot, f_plot, levels = levels, cmap=cmap2)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

图片保存

fig = plt.figure(figsize=(x_long,y_long))
ax = plt.subplot()
ax.contourf(grid_x_plot, grid_y_plot, f_plot, levels=levels, colors = Colors)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)

ax.set_xticks([])
ax.set_yticks([])
plt.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0)
plt.margins(0, 0)

 # 输出为二进制流
canvas = fig.canvas
buffer = io.BytesIO()  # 获取输入输出流对象
canvas.print_png(buffer)  # 将画布上的内容打印到输入输出流对象
data = buffer.getvalue()  # 获取流的值
buffer.close()
plt.close()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/604176
推荐阅读
相关标签
  

闽ICP备14008679号