原来的样子:
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,8),dpi=80)
x = range(2,26,2)
y = [15,13,14,5,17,20,25,26,24,22,18,15]
plt.plot(x,y)
plt.savefig("./sig_size.png")
plt.show()
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,8),dpi=80)
x = range(2,26,2)
y = [15,13,14,5,17,20,25,26,24,22,18,15]
plt.plot(x,y)
plt.xticks(x)
plt.show()
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,8),dpi=80)
x = range(2,26,2)
y = [15,13,14,5,17,20,25,26,24,22,18,15]
plt.plot(x,y)
# plt.xticks(x)
plt.xticks(x[::2])
plt.show()
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,8),dpi=80)
x = range(2,26,2)
y = [15,13,14,5,17,20,25,26,24,22,18,15]
plt.plot(x,y)
# plt.xticks(x)
# plt.xticks(x[::2])
plt.xticks(range(2,26))
plt.show()
25不想要
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,8),dpi=80)
x = range(2,26,2)
y = [15,13,14,5,17,20,25,26,24,22,18,15]
plt.plot(x,y)
# plt.xticks(x)
# plt.xticks(x[::2])
plt.xticks(range(2,25))
plt.show()
加上0.5
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,8),dpi=80)
x = range(2,26,2)
y = [15,13,14,5,17,20,25,26,24,22,18,15]
plt.plot(x,y)
# plt.xticks(x)
# plt.xticks(x[::2])
plt.xticks(range(2,25,0.5))
plt.show()
发现间隔0.5会报错
解决办法:列表2,,25,3,3.5,4,4.5,。。。。。。。。
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,8),dpi=80)
x = range(2,26,2)
y = [15,13,14,5,17,20,25,26,24,22,18,15]
plt.plot(x,y)
_xticks_lables = [i/2 for i in range(4,49)]
plt.xticks(_xticks_lables)
plt.show()
ok
但是太密集了
取步长每隔3取一个
列表的取步长
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,8),dpi=80)
x = range(2,26,2)
y = [15,13,14,5,17,20,25,26,24,22,18,15]
plt.plot(x,y)
_xticks_lables = [i/2 for i in range(4,49)]
plt.xticks(_xticks_lables[::3])
plt.show()
一定范围
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,8),dpi=80)
x = range(2,26,2)
y = [15,13,14,5,17,20,25,26,24,22,18,15]
plt.plot(x,y)
_xticks_lables = [i/2 for i in range(4,49)]
plt.xticks(range(25,50))
plt.show()
y轴
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,8),dpi=80)
x = range(2,26,2)
y = [15,13,14,5,17,20,25,26,24,22,18,15]
plt.plot(x,y)
_xticks_lables = [i/2 for i in range(4,49)]
plt.xticks(range(25,50))
plt.yticks(range(min(y),max(y)+1))
plt.show()
答案见下期