[英]pandas - plotting lines and markers with different zorders?
我試圖從pandas
數據框中繪制散布的線條和標記,但是在某些情況下,線條最終會繪制在標記的頂部。 有什么方法可以分別設置線條和標記的zorder
,以確保無論序列如何,標記始終繪制在任何線條的頂部? 例如,類似於marker_zorder=2, line_zorder=1
例如,以下代碼:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'x': [1, 5, 10],
'y1': [24, 7, 14],
'y2': [14, 6, 35]})
fig, ax = plt.subplots(figsize=(3, 5))
df.plot.line(x='x', ls='--', marker='.', ms=15, ax=ax)
ax.set_ylim(bottom=0)
plt.savefig('test.png', bbox_inches='tight')
產生此圖:
我們可以看到橙色線的地方是藍色標記。
不,沒有諸如marker_zorder
這樣的東西。 但是您可以兩次繪制數據,一次繪制為一條線,一次繪制在頂部。
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'x': [1, 5, 10],
'y1': [24, 7, 14],
'y2': [14, 6, 35]})
fig, ax = plt.subplots(figsize=(3, 5))
df.plot.line(x='x', ls='--', ax=ax)
# Reset prop cycle to obtain the same colors for the next plot
ax._get_lines.set_prop_cycle(plt.rcParams["axes.prop_cycle"])
df.plot.line(x='x', ls='', marker='.', ms=15, ax=ax, legend=False)
ax.set_ylim(bottom=0)
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.