我想創建這樣的圖表:

圖中只有前半部分是對數刻度。我嘗試使用兩個刻度 y 軸,但我無法將新軸從 0 開始移動。可以移動新軸嗎?或者還有其他方法,如何獲得這個圖?
# dummy data
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
y = [10000, 200000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 100001, 12000]
y2 = [1, 2, 45, 4, 5, 6, 2, 8, 9, 10, 11, 1]
fig, ax1 = plt.subplots(figsize=(5, 5), dpi=80)
ax2 = ax1.twinx()
# plot data
ax1.bar(x, y, color=color, log=True)
ax2.bar(x, y2,color=color)
ax2.invert_yaxis()
uj5u.com熱心網友回復:
您可以通過組合兩個圖來繪制它,這似乎是提供的輸出正在執行的操作:
# dummy data
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
y = [10000, 200000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 100001, 12000]
y2 = [1, 2, 45, 4, 5, 6, 2, 8, 9, 10, 11, 1]
fig = plt.figure()
gs = fig.add_gridspec(2, hspace=0)
axs = gs.subplots(sharex=True, sharey=False)
fig.suptitle('Your title')
axs[0].bar(x, y, log=True)
axs[1].bar(x, y2)
axs[1].invert_yaxis()

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/473881.html
標籤:Python python-3.x matplotlib 图形 数据可视化
上一篇:如何控制注釋箭頭
