可以使用“断开”轴
matplotlib example
.这将是定制版:
import matplotlib.pylab as plt
import numpy as np
x = []
year = 2017
for i in range(104):
j = i+1
if j <= 52:
x.append(year * 100 + j)
else:
k = j - 52
x.append(((year+1) * 100 ) + k)
np.random.seed(1)
values = np.random.randint(low=0, high=5000, size=104)
df = pd.DataFrame.from_dict({'year_week': x, 'values': values})
f,(ax,ax2) = plt.subplots(1,2,sharey=True, facecolor='w', figsize=(10,10))
# plot the same data on both axes
ax.plot(df['year_week'], df['values'])
ax2.plot(df['year_week'], df['values'])
ax.set_xlim(201700,201753)
ax2.set_xlim(201800,201853)
# hide the spines between ax and ax2
ax.spines['right'].set_visible(False)
ax2.spines['left'].set_visible(False)
ax.yaxis.tick_left()
ax.tick_params()
ax2.yaxis.tick_right()
#this gets rid of scientific notation, so it's more readable
ax.ticklabel_format(useOffset=False)
ax2.ticklabel_format(useOffset=False)
plt.show()
输出:
更重要的是,似乎有一个专门针对这个特定问题的软件包:
Brokenaxes