我想改变数字之间的间隔的大小。很明显,x轴是从10到26。但我希望每个整数都能显示出来: 10,11,12,13等等。我还希望柱状图的宽度为.5,这样我就可以有一个10.5到11或24到24.5 etc...because的柱状图,否则,python会输出柱状图,柱状图的柱状图是随机的和未确定的。这就是我所拥有的:
import random
import numpy
from matplotlib import pyplot
import numpy as np
data = np.genfromtxt('result.csv',delimiter=',',skip_header=1, dtype=float)
magg=[row[5] for row in data]
magr=[row[6] for row in data]
bins = numpy.linspace(10, 26)
pyplot.hist(magg, bins, alpha=0.5, color='g', label='mag of g')
pyplot.hist(magr, bins, alpha=0.5, color='r', label='mag of r')
pyplot.legend(loc='upper left')
pyplot.show()发布于 2014-06-03 05:30:17
使用轴定位器,特别是MultipleLocator。构建您的示例,它将变成这样:
import matplotlib.pyplot as plt
import numpy as np
x = np.random.random_integers(low=10, high=27, size=37)
bins = np.linspace(10, 26)
fig, ax = plt.subplots()
hist = ax.hist(x, bins, alpha=0.5, color='g', label='mag of g')
ax.xaxis.set_major_locator(plt.MultipleLocator(1))

https://stackoverflow.com/questions/24003485
复制相似问题