如何在RadioButtons小部件上获得窄宽度和较大的高度,并且仍然具有不重叠的圆形单选按钮?

时间:2016-04-09 18:21:13

标签: python matplotlib matplotlib-widget

如何在RadioButtons小部件上获得窄宽度和较大的高度,并且仍然具有不重叠的圆形单选按钮?

plt.figure()
rax = plt.axes([0.1, 0.1, 0.6, 0.6], frameon=True ,aspect='equal')
labels = [str(i) for i in range(10)]
radios = RadioButtons(rax, labels)
for circle in radios.circles: # adjust radius here. The default is 0.05
    circle.set_radius(0.02)
plt.show()

上面的工作原理是因为它将轴实例的宽度和高度设置为0.6,但我希望宽度为0.1,高度为0.6:

plt.figure()
rax = plt.axes([0.1, 0.1, 0.1, 0.6], frameon=True, aspect='equal')
labels = [str(i) for i in range(10)]
radios = RadioButtons(rax, labels)
for circle in radios.circles: # adjust radius here. The default is 0.05
    circle.set_radius(0.02)
plt.show()

这只会使结果非常小,宽度为0.1×高度0.1(我想是因为aspect ='等于'正在使用。如果我删除后者,我得到这个: Radio buttons are not round, even though I set their radius to 0.02

我问的原因是这些单选按钮将是右侧边框的窄边栏。所以它应该是狭窄但很高。

1 个答案:

答案 0 :(得分:0)

您可以使用RadioButton补丁matplotlib.patches.Circle的属性height创建import matplotlib.pyplot as plt from matplotlib.widgets import RadioButtons plt.figure() rax = plt.axes([0.1, 0.1, 0.1, 0.6], frameon=True) labels = [str(i) for i in range(10)] radios = RadioButtons(rax, labels) rpos = rax.get_position().get_points() fh = fig.get_figheight() fw = fig.get_figwidth() rscale = (rpos[:,1].ptp() / rpos[:,0].ptp()) * (fh / fw) for circ in radios.circles: circ.height /= rscale plt.show() '后更改圆圈的高度:

aspect

重要的是,我们未在此处将equal设置为rax。相反,我们将人为地改变圆圈的高度。在上面的示例中,我通过使用Sub Update_All_Graphs() Call SETWorksheets Dim Lastrow As Long Dim ShName As String Dim FindRow, FindRowNumber As Double Set FindRow = ScTotalWs.Range("AF10:AF47").Find(What:="Grand Total", LookIn:=xlValues) FindRowNumber = FindRow.Row Lastrow = FindRowNumber - 1 ScTotalWs.ChartObjects("1_EOST").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Range("AJ10:AJ" & Lastrow & ", AK10:AK" & Lastrow & ", AL10:AL" & Lastrow) End Sub 轴的位置来计算缩放高度的程度。请注意,我们还需要考虑该数字的宽高比。

enter image description here