看下面的图表。在这个图表中,我想画一个圆心坐标为(45,0)的圆。但是,正如您所见,图表的底端是零,我的圆的一半没有显示出来。所以,我需要把这张图表再往下延伸一点。”“边距”轴法(利润率())不起作用,因为此图表的底线是零,零乘以任何数字都等于零。在
注意:请不要像斧头组(…)或斧头套件(...). 我在寻找解决这类问题的一般方法。在
Code
import matplotlib.pyplot as plt
import numpy as np
values = np.array([0.00388632352941, 0.00375827941176, 0.00355033823529, 0.00328273529412, 0.00294677941176, 0.00272142647059, 0.00246463235294, 0.00227766176471, 0.00213151470588, 0.00202594117647, 0.00183544117647, 0.00162102941177, 0.00148372058824, 0.00128380882353, 0.00112252941176, 0.000931544117647, 0.000786573529412, 0.000658220588235, 0.000584485294118, 0.000524044117647, 0.000562485294118, 0.000716441176471, 0.000872617647059, 0.00109039705882, 0.00124138235294, 0.00136894117647, 0.00143985294118, 0.00134760294118, 0.00121794117647, 0.00112772058824, 0.00109435294118, 0.00102432352941, 0.00101069117647, 0.00102417647059, 0.00104895588235, 0.00101776470588, 0.00101494117647, 0.000885558823529, 0.00078075, 0.000752647058824, 0.000667691176471, 0.000593220588236, 0.000658647058823, 0.000742117647059, 0.000651470588235, 0.000604647058824, 0.000584573529412, 0.00049530882353, 0.000281235294118, 0.000355029411765])
fig, ax = plt.subplots()
ax.bar(np.arange(values.shape[0]), values)
plt.show()
问题中没有圆圈,所以我的答案也没有圆圈。
为了使绘图中的数据周围有一些空间,可以使用
ax.margins(y=ymargin)
,其中ymargin
是要在数据的每一侧添加的空间百分比。一、 如果数据从0变为1,并且加上ymargin = 0.1
的边距,则ylimit将是(-0.1, 1.1)
。(这与一个限制是否为零无关。)现在,默认情况下,这对条形图不起作用,因为在一般情况下,条形图不希望从空中某处开始,而不是从下轴开始。使用一个名为
use_sticky_edges
的标志来控制这种行为。我们可以将此标志设置为False
,以返回应用于轴两端的边距行为。为了生效,我们需要稍后调用ax.autoscale_view
。在相关问题 更多 >
编程相关推荐