pythonmatplotlib图例和注释(代码片段) | 您所在的位置:网站首页 › 折线图注释 › pythonmatplotlib图例和注释(代码片段) |
pythonmatplotlib图例和注释(代码片段) """ 图例和注释 图例参数: 1. bbox_to_anchor: 图例的放置位置: 是正归化之后的坐标(相对于整个坐标系的正规化值), 4个值分别为左下角坐标, 宽, 高 具体的调整参考官网: http://matplotlib.org/api/legend_api.html?highlight=legend#module-matplotlib.legend 也可以参考博客: http://blog.csdn.net/RobertChenGuangzhi/article/details/49719467 2. loc: 位置代号, 参考官网, 也可以用字符串, 例如'upper center' 3. ncol: 图例的列数 4. fancyBox 5. shadow: 阴影 6. mode: None or expand 指定是否将图例按照坐标轴展开 7. borderaxespad: 指定图例和坐标轴的padding间隔大小, 设置为0, 则不padding """ from matplotlib.pyplot import * # generate different normal distributions x1 =np.random.normal(30, 3, 100) x2 = np.random.normal(20, 2, 100) x3 = np.random.normal(10, 3, 100) # lable指定图例的标签, 与图例(legend)结合使用 plot(x1, label='plot') plot(x2, label='2nd plot') plot(x3, label='last plot') # 图例 legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=3, mode="expand", borderaxespad=0.) # 关键点注释, xycoords+xytext两个参数指定了文本放置的位置 annotate("Important value", (55,20), xycoords='data', xytext=(5, 38), arrowprops=dict(arrowstyle='->')) show()相关内容 pythonmatplotlib-重新添加spines来覆盖样式表(代码片段) 我在matplotlib中制作了一个3x3子图,并使用以下样式表进行美观: plt.style.use('ggplot')我喜欢样式表,但我想要显示左侧脊柱。以下代码适用于与我的9斧头交互,但它不会重新添加脊椎(其他一切正常)。 for ax in axes: ax.set_xlim(0,100) ax.tick_params(axis=u'both', which=u'both',length=0) ax.set_xticklabels(['0%','20%','40%','60%','80%','100%'],rotation = 45, fontname="Arial", fontsize=9) ax.set_yticklabels(themes,fontname="Arial", fontsize=9) ax.spines['left'].set_visible(True)样式表一旦导入就不可编辑吗?或者我做错了什么? 谢谢 答案在ggplot风格,刺仍然存在,它更像是"axes.edgecolor" that is white。 因此,解决方案可以是将其变为黑色,而是关闭除左侧脊柱之外的所有部分。 import matplotlib.pyplot as plt rc = "axes.spines.bottom" : False, "axes.spines.top" : False, "axes.spines.right" : False, "axes.edgecolor" : "black" plt.style.use(("ggplot", rc))我认为这种风格的刺没有设置隐形但颜色适应,所以你可以尝试例如 ax.spines['left'].set_color('k')如果你错过了你可以添加的刻度线 ax.yaxis.set_tick_params(size=3) |
CopyRight 2018-2019 实验室设备网 版权所有 |