等轴散景图 [英] Bokeh Plot with equal axes

查看:78
本文介绍了等轴散景图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PythonBokeh创建了一个Plot(请参见代码).

I created a Plot with the Python library Bokeh (see code).

from bokeh.plotting import *

figure()
hold()
rect([1,3], [1,1], [1,0.5], [1,0.5])
patch([0,0,4,4], [2,0,0,2], line_color="black", fill_color=None)
show()

如何使用命令axis('equal')用matplotlib表示具有相等轴的正方形(宽度和高度相同的矩形)?

How can I represent the squares (rectangle with the same width and height) with equal axes as in matplotlib with the command axis('equal')?

http://matplotlib.org/examples/pylab_examples/axis_equal_demo.html

我可以选择更改图的宽度和高度或定义轴范围来解决此问题,但我认为应该有一个更明智的选择.

I see the option to change the width and height of the plot or define the axis range to solve this problem but I think, there should be a smarter alternative.

注意:我正在使用Python v.2.7.8Bokeh v.0.6.1.

推荐答案

从Bokeh 0.12.7开始,已实现此功能.绘图现在可以接受两个新属性. match_aspect,当设置为true时,它将使数据空间的长宽比与图的像素空间匹配.例如,以数据单位绘制的正方形现在也将成为以像素为单位的完美正方形.

As of Bokeh 0.12.7, this feature has been implemented. Plots can now accept two new properties. match_aspect which, when set to true, will match the aspect of the data space to the pixel space of the plot. For example, squares drawn in data units will now be perfect squares in pixel units as well.

p = figure(match_aspect=True)
p.circle([-1, +1, +1, -1], [-1, -1, +1, +1])

aspect_scale使您可以通过在match_aspect进行的宽高比校正的顶部指定一个乘数来进一步控制宽高比.

aspect_scale allows you to further control the aspect ratio by specifying a multiplier on top of the aspect correction made by match_aspect.

p = figure(aspect_scale=2)
p.circle([-1, +1, +1, -1], [-1, -1, +1, +1])

p = figure(aspect_scale=0.5)
p.circle([-1, +1, +1, -1], [-1, -1, +1, +1])

这篇关于等轴散景图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆