0

我需要在子图中的 x 轴上放置小刻度。这是我的脚本,我需要在其中更改什么?

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from matplotlib import rc
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
import matplotlib.ticker as tkr
from pylab import text
import matplotlib.patches as mpatches
import matplotlib.font_manager as font_manager
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter)

  
a = open("file1.txt").read().splitlines()
b = open("file2.txt").read().splitlines()
c = open("file3.txt").read().splitlines()

variable1 = np.ravel(a).astype(np.float)
variable2 = np.ravel(b).astype(np.float)
variable3 = np.ravel(c).astype(np.float)

fig, ax = plt.subplots(figsize=(15,30))
#fig, ax = plt.subplots(figsize=(14,10))
plt.subplots_adjust(wspace=0.08, hspace=0.05)

font_path = '/Library/Fonts/Helvetica.ttf'
font_prop = font_manager.FontProperties(fname=font_path, size=20)

plt.subplot(311)
plt.xticks(size=20)
plt.yticks(size=20)
plt.hist(variable1, bins=100, histtype='bar', density=True, ec='red', color='red', alpha=0.5)
plt.grid()
plt.tight_layout()
plt.ylim(0,90)
plt.yticks(np.arange(0, 100, 10))
plt.xlim(-0.02,0.5)
plt.xticks(np.arange(0, 0.5, 0.05))
ax.xaxis.set_major_locator(MultipleLocator(0.5))
ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
ax.xaxis.set_minor_locator(MultipleLocator(5))
ax.minorticks_on()

plt.show()

作为第一次尝试,我正在尝试在第一个子图中放置小刻度。任何人都可以帮助我并支持我吗?非常感谢

4

0 回答 0