发布于2019-12-04 14:09 阅读(2054) 评论(0) 点赞(5) 收藏(2)
为了达到视觉效果,我希望可以删除圆外的网格,而仅将其保留在圆内。
顺便说一句,如何用红色填充单元格[[8,9],[9,10]),我的意思是,x = 8右侧和y = 9下方的单元格。
我的代码在下面,并且还附有当前图片。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.transforms import BlendedGenericTransform
fig, ax = plt.subplots()
ax.text(0, -0.02, 'y', transform=BlendedGenericTransform(ax.transData, ax.transAxes), ha='center')
ax.text(1.01, 0, 'x', transform=BlendedGenericTransform(ax.transAxes, ax.transData), va='center')
ax.set_xticks(np.arange(0,side+1,1))
ax.set_yticks(np.arange(0,side+1,1))
plt.grid()
ax.xaxis.tick_top()
plt.gca().invert_yaxis()
circle = plt.Circle((15, 15), radius=15, fc='w')
plt.gca().add_patch(circle)
fig.set_size_inches(18.5, 10.5)
诀窍是将clip_path
属性设置为网格艺术家
这是一个简化的(最小)示例:
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
# draw the circle
circle = plt.Circle((15, 15), radius=15, fc='w')
ax.add_patch(circle)
# settings for the axes
ax.grid()
ax.set_xlim(0,30)
ax.set_ylim(0,30)
ax.set_aspect(1)
# clip the gridlines
plt.setp(ax.xaxis.get_gridlines(), clip_path=circle)
plt.setp(ax.yaxis.get_gridlines(), clip_path=circle)
plt.show()
结果:
作者:黑洞官方问答小能手
链接:https://www.pythonheidong.com/blog/article/167618/a48a95cc048a84e1aa3d/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!