我尝试用包含多个基数(a、C、G、T、U1和U2)的数据的pd.DataFrame
图创建一个sns.catplot
图。
我的目标是只绘制由df ['environment']
值决定亮度的标记,因此没有线条、方框或任何东西。我也尝试了一些cycler.cycler (color = colourlist)
的东西,但是“情节不想选择”超过三种颜色
import matplotlib.pyplot as plt
import matplotlib
import seaborn as sns
import pandas as pd
import numpy as np
import cycler
import os
sns.set (style = 'white', color_codes = True, palette = ["#FF0000", "#0000FF", "#00FF00", "#C03030", "#3030C0", "#30C030"])
colourlist = np.array ([ [0, 0, 0] ])
for v in [0, 45] :
for s in [0, 45] :
for h in [0, 120, 240] :
try :
H, S, V = h / 360., (100 - s) / 100., (100 - v) / 100.
colourlist = np.append (colourlist, [ [H, S, V] ], axis = 0)
except :
pass
colourlist = np.delete (colourlist, 0, 0)
matplotlib.rcParams ['axes.prop_cycle'] = cycler.cycler (color = colourlist)
matplotlib.rcParams ['image.cmap'] = 'hsv'
matplotlib.rcParams ['savefig.transparent'] = True
matplotlib.rcParams ['savefig.format'] = 'eps'
matplotlib.rcParams ['axes.xmargin'] = 0
matplotlib.rcParams ['axes.ymargin'] = 0
matplotlib.rcParams ['figure.frameon'] = False
matplotlib.spines.rcParams ['axes.spines.right'] = False
matplotlib.spines.rcParams ['axes.spines.top'] = False
matplotlib.rcParams ['xtick.bottom'] = True
matplotlib.rcParams ['ytick.left'] = True
file = os.path.join (os.environ ['HOME'], 'Data.csv')
with open (file, 'r') as f :
df = pd.read_csv (f, index_col = 0, header = 0, thousands = None, decimal = '.')
df ['base'] = df ['base'].str.upper ()
#df ['method'] = df ['method'].str.upper ()
df = df.sort_values (['charge', 'base', 'environment'])
sns.catplot (jitter = False, data = df, x = 'base', y = 'energy', hue = 'charge', palette = ["#000FFF", "#00FF00", "#FF0000", "#00FFFF", "#FF00FF", "#FFFF00"], order = ['A', 'C', 'U1', '', 'G', 'T', 'U2'])
~/Data.csv:
,environment,base,charge,energy,method
0,pbs,A,neg,0.34835,1
1,pbs,C,neg,0.40194,2
2,pbs,G,neg,0.34959,1
3,pbs,T,neg,0.40738,2
4,pbs,U1,neg,0.34904,2
5,pbs,U2,neg,0.40016,2
6,pbs,A,neu,0.40151,3
7,pbs,C,neu,0.34494,3
8,pbs,G,neu,0.40193,3
9,pbs,T,neu,0.34458,3
10,pbs,U1,neu,0.34646,3
11,pbs,U2,neu,0.40871,3
12,pbs,A,pos,0.34047,2
13,pbs,C,pos,0.40157,2
14,pbs,G,pos,0.34232,2
15,pbs,T,pos,0.40854,2
16,pbs,U1,pos,0.34611,2
17,pbs,U2,pos,0.34414,2
18,polymeric,A,neg,0.28333,2
19,polymeric,C,neg,0.46908,3
20,polymeric,G,neg,0.33224,3
21,polymeric,T,neg,0.35825,1
22,polymeric,U1,neg,0.33033,3
23,polymeric,U2,neg,0.39167,3
24,polymeric,A,neu,0.36964,2
25,polymeric,C,neu,0.33979,2
26,polymeric,G,neu,0.41815,3
27,polymeric,T,neu,0.30786,2
28,polymeric,U1,neu,0.40727,1
29,polymeric,U2,neu,0.36719,3
30,polymeric,A,pos,0.38173,1
31,polymeric,C,pos,0.35060,3
32,polymeric,G,pos,0.37617,1
33,polymeric,T,pos,0.44172,2
34,polymeric,U1,pos,0.31267,3
35,polymeric,U2,pos,0.34478,2
我想到了类似的事情
sns.scatterplot (data = df, x = 'base', y = 'energy', hue = 'charge', x_order = ['A', 'C', 'U1', '', 'G', 'T', 'U2'], brightness = np.where (df ['environment'] == 'pbs', 1., .5) ).
我可以用matplotlib
来绘制这个(数据;pandas.DataFrame
)吗?代码是什么样子的
目前没有回答
相关问题 更多 >
编程相关推荐