在极坐标图中圆形并绘制外部刻度 [英] Round and draw external scale in polar plot

查看:56
本文介绍了在极坐标图中圆形并绘制外部刻度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了这个

我尝试使用以下行对值进行四舍五入

scale_ax.set_yticks(round(float(ax.get_yticks()), 2))

代替

scale_ax.set_yticks(ax.get_yticks())

但这并没有改善我的比例,如下所示,尽管我的 ticks 现在四舍五入了:

解决方案

您需要定义或更改图形的 ylimit.

scale_ax.set_ylim(ax.get_rorigin(), ax.get_rmax())

以上线用于定义添加比例的最小值和最大值.

I've found this answer to a question where an approach for a scale outside a polar plot is provided (the add_scale function there). I tried to apply this to my data as well and it almost worked out. As shown in the picture, there is an issue at the top of the scale bar. How can I remove this little too long part of the scale?

Second question is: How can I round the values in this scale to two digits. I've had a look at this question, but it didn't work out.

I'll re-post the code here with all credits to @lostin.

# to control how far the scale is from the plot (axes coordinates)    
def add_scale(ax, X_OFF, Y_OFF):
    # add extra axes for the scale
    X_OFFSET = X_OFF
    Y_OFFSET = Y_OFF
    rect = ax.get_position()
    rect = (rect.xmin-X_OFFSET, rect.ymin+rect.height/2-Y_OFFSET, # x, y
            rect.width, rect.height/2) # width, height
    scale_ax = ax.figure.add_axes(rect)
   # if (X_OFFSET >= 0):
        # hide most elements of the new axes
    for loc in ['right', 'top', 'bottom']:
        scale_ax.spines[loc].set_visible(False)
#    else:
#        for loc in ['right', 'top', 'bottom']:
#            scale_ax.spines[loc].set_visible(False)
    scale_ax.tick_params(bottom=False, labelbottom=False)
    scale_ax.patch.set_visible(False) # hide white background
    # adjust the scale
    scale_ax.spines['left'].set_bounds(*ax.get_ylim())
    # scale_ax.spines['left'].set_bounds(0, ax.get_rmax()) # mpl < 2.2.3
    scale_ax.set_yticks(ax.get_yticks())
    scale_ax.set_ylim(ax.get_rorigin(), ax.get_rmax())
    # scale_ax.set_ylim(ax.get_ylim()) # Matplotlib < 2.2.3

Edit:

I tried to round the values with the following line

scale_ax.set_yticks(round(float(ax.get_yticks()), 2))

instead of

scale_ax.set_yticks(ax.get_yticks())

but this didn't improve my scale as shown below, although my ticks are rounded now:

解决方案

You need to define or change ylimit for your graph.

scale_ax.set_ylim(ax.get_rorigin(), ax.get_rmax())

Above line is used to define min and max value on the added scale.

这篇关于在极坐标图中圆形并绘制外部刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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