[英]Matplotlib loglog plot ,set_xlim
In the code written below, I am trying to get the x tick labels by using the function get_xticks()
after setting a limit to x axis values which is 1,2.在下面编写的代码中,我试图在将 x 轴值设置为 1,2 后使用 function get_xticks()
获取 x 刻度标签。 So I was expecting values between 1 to 2 from get_xticks()
.所以我期望get_xticks()
的值在 1 到 2 之间。 But instead I am getting set of values [0.1,1,10,100]
.但相反,我得到了一组值[0.1,1,10,100]
。
I could not understand why it is giving these values.我不明白为什么它给出这些值。 Is it because of loglog plot?是因为loglog plot? If so how this limit is related to the the values that I am getting now?如果是这样,这个限制与我现在得到的值有什么关系?
time = [1, 2, 3, 4]
position = [10, 20, 30, 40]
plt.xlabel('Time (hr)')
plt.ylabel('Position (km)')
fig = plt.figure(1)
ax = fig.add_subplot(111)
ax.loglog(time,position)
xlim = [1,2]
ax.set_xlim(xlim)
xlabels = ax.get_xticks()
Yes, it's because the plot is loglog.是的,这是因为 plot 是 loglog。 What you are seeing in the plot is actually one major tick (10^0) and the other 5 are minor ticks.您在 plot 中看到的实际上是一个主要刻度 (10^0),另外 5 个是次要刻度。
ax.get_xticks
has an argument minor=
which will return the minor ticks instead of the major ticks, if set to True
ax.get_xticks
有一个参数minor=
如果设置为True
,它将返回次要刻度而不是主要刻度
print(ax.get_xticks()) # returns the major ticks
# [ 0.1 1. 10. 100. ]
print(ax.get_xticks(minor=True)) # returns the minor ticks
# [1.2000000000000002, 1.4000000000000001, 1.6, 1.8, 2.0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.