如何使用set_xlabel标记正x轴和负x轴? [英] How to label Positive and negative x-axis using set_xlabel?

查看:321
本文介绍了如何使用set_xlabel标记正x轴和负x轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下代码中,我创建了4轴.正负x和y轴.我想将正x轴标记为c1,将负x轴标记为c2,将正y轴标记为h1,将负y轴标记为h2.如果我使用ax.set_xlabel,它将标记整个x轴.但是我想为正负x轴分配不同的标签.我怎样才能做到这一点?

In the following code I have created 4 axis. Positive and negative x and y axis. I want to label positive x-axis as c1,negative x-axis as c2, positive y-axis as h1 and negative y-axis as h2. If I use ax.set_xlabel it will label whole x-axis. But I want to assign different labels to positive and negative x-axis. How can I do that?

`fig = plt.figure()
ax= fig.add_subplot(111)
x = [0.1,0.2,-0.2,0.3]
y=[0.3,-0.2,0.4,0.3]
ax.scatter(x,y)
ax.set_xlim([-0.5, 0.5])
ax.set_ylim([-0.5, 0.5])


ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.spines['bottom'].set_position('zero')`

推荐答案

您可以使用matplotlib.pyplot.text(x, y, s, fontdict=None, withdash=False, **kwargs)在图形上的指定位置书写文本. x和y对应于字符串的位置,s是字符串.

You can use matplotlib.pyplot.text(x, y, s, fontdict=None, withdash=False, **kwargs) to write text at a specified location on your graph. x and y correspond to the location of the string, s is the string.

这篇关于如何使用set_xlabel标记正x轴和负x轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆