改变默认×幅度直方图matplotlib(changing default x range in h

2019-07-31 05:03发布

我想更改默认的X系列的直方图。 的数据的范围为7〜12。然而,在默认情况下直方图开始就在7和13处结束我希望它开始在6.5和12.5结束。 然而,蜱应该去从7到12.How做呢?

import asciitable 
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import pylab
from pylab import xticks

data = asciitable.read(file)
hmag = data['col8']
visits = data['col14']
origin = data['col13']


n, bins, patches = plt.hist(hmag, 30, facecolor='gray', align='mid')
xticks(range(7,13))
pylab.rc("axes", linewidth=8.0)
pylab.rc("lines", markeredgewidth=2.0) 
plt.xlabel('H mag', fontsize=14)
plt.ylabel('# of targets', fontsize=14)
pylab.xticks(fontsize=15)
pylab.yticks(fontsize=15)
plt.grid(True)
plt.savefig('hmag_histogram.eps', facecolor='w', edgecolor='w', format='eps')
plt.show()

Answer 1:

plt.hist(hmag, 30, range=[6.5, 12.5], facecolor='gray', align='mid')


Answer 2:

import matplotlib.pyplot as plt


...


plt.xlim(xmin=6.5, xmax = 12.5)


文章来源: changing default x range in histogram matplotlib