如何在单个散点图中添加注释的颜色
我需要如下图(来自两个图的图片中的图片中的一个图)上涂上注释。
因此,我想在下面旋转此图像
,就图上的每个点的颜色注释而言,也添加了一个传奇,就像下面的图像
i.sstatic.net/3xfka.png IS:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.patches as mpatches
from matplotlib.pyplot import figure
figure(figsize=(10, 8), dpi=120)
from scipy.stats import t
plt.close('all')
data = np.array([
[22.8, 22.8],
[19.6, 0.3],
[0.3, 3.1],
[8.9, -1.7],
[13.7, 4.8],
[14.7, -0.7],
[1.9, -2.6],
[-1.8, -0.03],
[-3, -5.7],
[-5.9, -1.5],
[-13.4, -3.9],
[-5.7, -21.5],
[-6.8, -7.7],
])
custom_annotations = ["K464E", "K472E", "R470E", "K464A", "M155E", "K472A", "M155A", "Q539A", "M155R", "D244A", "E247A", "E247R", "D244K"]
plt.scatter(data[:,0], data[:,1], marker='o', c=data[:,1], edgecolors='black', linewidths=1, alpha=0.75)
#plt.colorbar(orientation='horizontal')
plt.xlabel(r'$\Delta V_{0.5}$ Apo wild-type mHCN2 (mV)')
plt.ylabel(r'$\Delta \psi$ cAMP-bound wild-type mHCN2 (mV)')
plt.axvline(0, c=(.5, .5, .5), ls= '--')
plt.axhline(0, c=(.5, .5, .5), ls= '--')
classes = ["K464E", "K472E", "R470E", "K464A", "M155E", "K472A", "M155A", "Q539A", "M155R", "D244A", "E247A", "E247R", "D244K"]
class_colours = ["r", "r", "r", "r", "r", "r", "g", "g", "b", "b", "b", "b", "b"]
plt.annotate(txt, (data[i,0], data[i,1]))
plt.legend(recs,classes,loc=(1.04,0))
plt.show()
for循环中的某些内容是以不正确的方式丢失或写入的,关于点颜色注释和传说,应与帖子中的图像相同,应将其放置在图外。
i need to color annotate as in the image below (from a panel of two plots) in a single plot.
so, i would want to turn this image below
to this, in terms of the color annotation of each point on the plot, also adding a legend just as the image below
my full code is:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.patches as mpatches
from matplotlib.pyplot import figure
figure(figsize=(10, 8), dpi=120)
from scipy.stats import t
plt.close('all')
data = np.array([
[22.8, 22.8],
[19.6, 0.3],
[0.3, 3.1],
[8.9, -1.7],
[13.7, 4.8],
[14.7, -0.7],
[1.9, -2.6],
[-1.8, -0.03],
[-3, -5.7],
[-5.9, -1.5],
[-13.4, -3.9],
[-5.7, -21.5],
[-6.8, -7.7],
])
custom_annotations = ["K464E", "K472E", "R470E", "K464A", "M155E", "K472A", "M155A", "Q539A", "M155R", "D244A", "E247A", "E247R", "D244K"]
plt.scatter(data[:,0], data[:,1], marker='o', c=data[:,1], edgecolors='black', linewidths=1, alpha=0.75)
#plt.colorbar(orientation='horizontal')
plt.xlabel(r'$\Delta V_{0.5}$ Apo wild-type mHCN2 (mV)')
plt.ylabel(r'$\Delta \psi$ cAMP-bound wild-type mHCN2 (mV)')
plt.axvline(0, c=(.5, .5, .5), ls= '--')
plt.axhline(0, c=(.5, .5, .5), ls= '--')
classes = ["K464E", "K472E", "R470E", "K464A", "M155E", "K472A", "M155A", "Q539A", "M155R", "D244A", "E247A", "E247R", "D244K"]
class_colours = ["r", "r", "r", "r", "r", "r", "g", "g", "b", "b", "b", "b", "b"]
plt.annotate(txt, (data[i,0], data[i,1]))
plt.legend(recs,classes,loc=(1.04,0))
plt.show()
something in the for loop is missing or written in an incorrect way, the wished plot should be the same as the image in the post, with respect to points color annotation and the legend, which should be placed outside the plot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,要产生单独的注释,您的问题是没有循环。您需要为i放置
,在
plt.annotate 之前枚举(类)中的txt:,以确切地产生您想要的东西,但是,您需要执行stacter命令每个点,并将标签与每个点相关联,如下所示:
您需要进行一些次要的字体调整,因此所有内容都适合,也许将长传奇分为两三列。
但是,对于传说,您在图片中显示的内容似乎是多余的。似乎您想指出三个不同的数据。我建议将您的数据分为三种不同类型(代码中的类),并执行三个单独的时间,并将其放入类描述中。
这就是我要做的事情:
生产此内容:
First, to produce separate annotations, your problem is that there was no loop. You need to put
for i, txt in enumerate(classes):
before theplt.annotate
To produce exactly what you want, however, you need to execute the scatter command for each point, and associate a label to each point as follows:
You'll need to make some minor font adjustment so everything fits, perhaps splitting the long legend in two or three columns.
However, for the legend, what you show in the picture seems redundant. It seems like you want to indicate three different groups of data. I recommend to separate your data into the three different types (classes in your code) and execute scatter three separate times and put in the legend the class descriptions.
Here is how I would do it:
producing this: