matplotlib 中的中心原点
我需要帮助定制我的绘图。我希望画布看起来大致像 MacOS Grapher 中的默认 2D 图形模板(参见屏幕截图)。
澄清一下 - 我需要
- 一个中心轴和
- 一个网格(最好每 1 个单位有一个额外的深色网格)
- 轴线的箭头
- 在原点只有一个零(当我尽力而为时,我从 x 轴得到一个零,从 y 轴得到第二个零。),稍微向左移动,这样它就不会在 y 后面轴
我真的很感谢你的帮助!
I need help customizing my plots. I want the canvas to look approximately like the default 2D-graph template from MacOS's Grapher (see screenshot).
To clarify - I need
- a centered axis
- a grid (preferably with an additional darker grid every 1 unit)
- axislines with arrows
- only one zero at the origo (when I tried my best, I got one zero from the x-axis and a second one from the y-axis.), slightly moved to the left so it's not behind the y-axis
I really appreciate your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这绝对属于 matplotlib 带来的麻烦比其价值更大的范畴,但你就可以了。另外,对于基本情况,请查看文档中的居中脊柱演示。
您可以通过几种不同的方式来做到这一点,但为了获得最佳视觉效果,请考虑遵循以下内容。它远非完美,但相当灵活:
我故意没有将 x 和 y 主要刻度间隔设置为 1,但这很容易做到。
ax.xaxis.set_major_locator(MultipleLocator(1))
现在您只需调用
center_spines
即可执行以下操作:This definitely falls under the category of more trouble than it's worth with matplotlib, but here you go. Also, for the basic case, have a look at the centering spines demo in the documentation.
You can do this in a few different ways, but for the best visual effect, consider something along the lines of the following. It's far from perfect, but it's reasonably flexible:
I deliberately didn't set the x and y major tick intervals to 1, but that's easy to do.
ax.xaxis.set_major_locator(MultipleLocator(1))
Now you can just call
center_spines
to do something like this: