我试图生成一个图,其中x轴是几何序列,而y轴是0.0和1.0之间的数字。 我的代码如下所示:
form matplotlib import pyplot as plt plt.xticks(X) plt.plot(X,Y) plt.show()这会产生一个这样的情节:
如您所见,我明确地将x轴刻度设置为属于几何序列的刻度线。
我的问题:是否有可能使x-ticks均匀分布,尽管它们的价值,因为序列的初始条款很小,并且挤在一起。 有点像对数刻度,如果处理基数的力量是理想的,但对于几何序列则不是,我认为,就像这里的情况一样。
I am trying to generate a plot with x-axis being a geometric sequence while the y axis is a number between 0.0 and 1.0. My code looks like this:
form matplotlib import pyplot as plt plt.xticks(X) plt.plot(X,Y) plt.show()which generates a plot like this:
As you can see, I am explicitly setting the x-axis ticks to the ones belonging to the geometric sequence.
My question:Is it possible to make x-ticks evenly spaced despite their value, as the initial terms of the sequence are small, and crowded together. Kind of like logarithmic scale, which would be ideal if dealing with powers of a base, but not for a geometric sequence, I think, as is the case here.
最满意答案
您可以通过将变量绘制为参数化曲线的“自然”变量的函数来实现。 例如:
n = 12 a = np.arange(n) x = 2**a y = np.random.rand(n) fig = plt.figure(1, figsize=(7,7)) ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212) ax1.plot(x,y) ax1.xaxis.set_ticks(x) ax2.plot(a, y) #we plot y as a function of a, which parametrizes x ax2.xaxis.set_ticks(a) #set the ticks to be a ax2.xaxis.set_ticklabels(x) # change the ticks' names to x产生:
You can do it by plotting your variable as a function of the "natural" variable that parametrizes your curve. For example:
n = 12 a = np.arange(n) x = 2**a y = np.random.rand(n) fig = plt.figure(1, figsize=(7,7)) ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212) ax1.plot(x,y) ax1.xaxis.set_ticks(x) ax2.plot(a, y) #we plot y as a function of a, which parametrizes x ax2.xaxis.set_ticks(a) #set the ticks to be a ax2.xaxis.set_ticklabels(x) # change the ticks' names to xwhich produces:
更多推荐
发布评论