如何在matplotlib中限制y轴高度? [英] How do you limit the y-axis height in matplotlib?
问题描述
你如何限制matplotlib图中y轴的高度?我试图既显示x轴,又减小该1D图的图形高度.
How do you limit the height of the y-axis in matplotlib figure? I am trying to both display the x axis, and reduce the height of the figure for this 1D plot.
我尝试过设置刻度、图形大小、tight_layout、边距等,但都没有成功.
I have tried setting ticks, figure sizes, tight_layout, margin, etc. with no luck.
此外,无论我选择什么限制,更改 ylimits 只会跨越整个图形高度.
Also, changing the ylimits just spans the full figure height no matter what limits I choose.
import numpy as np
import matplotlib.pyplot as plot
from matplotlib import rcParams
x = np.array([3500])
y = np.array([0])
rcParams['toolbar'] = 'None'
plot.figure(num=None, figsize=(4, 1), dpi=80, facecolor='w')
plot.axes(frameon=False)
plot.yticks([0])
plot.xlim(0, 6000)
plot.ylim(-0.1, 0.1)
plot.plot(x, y, 'x', markersize=10)
plot.show()
当前数字:
所需数字:
推荐答案
只需将 figsize
更改为 (4, 0.3)
,我得到的东西或多或少看起来像您想要的输出(除了顶部有刻度,但也可以删除):
Simply changing figsize
to (4, 0.3)
, I get something that more or less looks like your desired output (except with ticks at the top as well, but those can also be removed):
这篇关于如何在matplotlib中限制y轴高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!