我有以下代码。它在Pandas中使用Matplotlib包装器:
import pandas as pd
import io
import matplotlib
import matplotlib.pyplot as plt
test=u"""Cell,Value
Bcells,0.056304
DendriticCells,0.3155388
Macrophages,0.131430
"""
tableau10=[ "#17BECF", "#BCBD22", "#7F7F7F", ]
toplot_df = pd.read_csv(io.StringIO(test))
toplot_df.set_index('Cell',inplace=True)
xlabels = toplot_df.index.values
barplot = toplot_df.plot(kind="bar", figsize=(17,17), \
color = tableau10, \
width=0.7,\
fontsize = 30,\
legend=False,
ylim = (0,0.5),
subplots=False)
ax = plt.gca()
ax.set_xticklabels(xlabels, rotation=30, ha='right')
# How to to make this to the back
plt.axhline(y=0.1, linewidth=1, color='r',zorder=1)
plt.xlabel("")
plt.ylabel("Score", fontsize=30, fontweight="bold")
它使这个数字:
如那里所述。我该如何做axhline
背景?我试过了,zorder
但是不行。
你只需要做zorder
的barplot
比更高zorder
的axhline
。在您的示例中,我只需要将选项添加zorder=2
到barplot = toplot_df.plot()
呼叫中即可。
import pandas as pd
import io
import matplotlib
import matplotlib.pyplot as plt
test=u"""Cell,Value
Bcells,0.056304
DendriticCells,0.3155388
Macrophages,0.131430
"""
tableau10=[ "#17BECF", "#BCBD22", "#7F7F7F", ]
toplot_df = pd.read_csv(io.StringIO(test))
toplot_df.set_index('Cell',inplace=True)
xlabels = toplot_df.index.values
barplot = toplot_df.plot(kind="bar", figsize=(17,17), \
color = tableau10, \
width=0.7,\
fontsize = 30,\
legend=False,
ylim = (0,0.5),
subplots=False,
zorder=2) ##### This is all I added
ax = plt.gca()
ax.set_xticklabels(xlabels, rotation=30, ha='right')
# How to to make this to the back
plt.axhline(y=0.1, linewidth=1, color='r',zorder=1)
plt.xlabel("")
plt.ylabel("Score", fontsize=30, fontweight="bold")
plt.show()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句