找回密码
 会员注册
查看: 18|回复: 0

Python绘图颜色、技巧汇总

[复制链接]

4

主题

0

回帖

13

积分

新手上路

积分
13
发表于 2024-9-9 17:34:08 | 显示全部楼层 |阅读模式
往期精彩内容:深度学习论文模型图的绘制与分享Python绘制高级图-代码分享Python绘制多分类ROC曲线引言在论文绘图中,最重要的是准确传达数据和信息。无论是实验结果图、统计图表还是概念图示,图像应当清晰明了地展示研究结果和观点。无论用什么软件,以下几个原则十分重要:数据准确性:确保图表中的数据准确无误,不要出现错误的标注或显示。清晰度和分辨率:图像的分辨率需要足够高,以便在打印或放大时仍然保持清晰度。确保图像的分辨率符合期刊的要求。图像格式:选择适合的图像格式,确保图像在不同环境下都能够清晰显示。配色和样式:选择合适的配色方案,确保图像的颜色搭配清晰明了,同时符合期刊的要求。图像说明和标注:图像应当配有清晰的说明和标注,以便读者理解图像所传达的信息。其中操作空间最高的当属配色和样式了。1 ython复现SCI论文插图经典配色下面参考顶刊SCI论文插图经典配色,利用python进行复现。SCI论文插图经典配色来源:知乎up主-阿昆的科研日常1.1计算Matplotlib中的RGB格式数值上述配色都是软件Matlab的RGB格式,其取值范围在0-255,而Python中的Matplotlib库中支持使用RGB格式取值范围通常在0到1之间,所以需要将每个颜色通道的取值除以255,以得到在0到1之间的标准化取值,按照以下方式转换:R_normalized=R/255 G_normalized=G/255 B_normalized=B/255比如复现经典配色实例No.017       clolor_zise=(0.267,0.16,0.353)clolor_zanglan=(0.255,0.243,0.522)clolor_shenlan=(0.188,0.408,0.553)clolor_lanlv=(0.122,0.573,0.545)clolor_lvse=(0.208,0.718,0.467)clolor_lvhuang=(0.569,0.835,0.259)clolor_huangse=(0.973,0.902,0.125)'运行运行2.2数据准备绘制某模型在0db、50db、40db、30db、20db噪声下的训练、验证、测试准确率的柱状图#数据labels=['0DB','50DB','40DB','30DB','20DB']train_accuracy=[99.93,99.86,99.85,99.82,99.70]validation_accuracy=[99.27,98.54,98.52,98.08,94.47]test_accuracy=[99.48,98.70,97.61,97.44,95.01]'运行运行2.3绘图#绘制柱状图plt.figure(figsize=(8,4),dpi=300)#柱子宽度比例width=0.15plt.bar(x,train_accuracy,width,label='TrainAccuracy',color=clolor_huangse)plt.bar([i+widthforiinx],validation_accuracy,width,label='ValidationAccuracy',color=clolor_lanlv)plt.bar([i+2*widthforiinx],test_accuracy,width,label='TestAccuracy',color=clolor_zise)#设置X轴标签plt.xlabel('Noiselevel')#设置Y轴标签plt.ylabel('Accuracy(%)')#设置X轴刻度plt.xticks([i+widthforiinx],labels)#隐藏上方和右侧的轴线plt.gca().spines['top'].set_visible(False)plt.gca().spines['right'].set_visible(False)#显示X轴和Y轴plt.gca().get_xaxis().tick_bottom()plt.gca().get_yaxis().tick_left()#添加数值标签rotation_angle='vertical'#设置文本旋转角度为垂直foriinx:plt.text(i,train_accuracy[i]+2,str(train_accuracy[i]),ha='center',va='bottom',fontsize=8,rotation=rotation_angle)plt.text(i+width,validation_accuracy[i]+2,str(validation_accuracy[i]),ha='center',va='bottom',fontsize=8,rotation=rotation_angle)plt.text(i+2*width,test_accuracy[i]+2,str(test_accuracy[i]),ha='center',va='bottom',fontsize=8,rotation=rotation_angle)#显示图例,设置列数为3plt.legend(loc='uppercenter',bbox_to_anchor=(0.5,1.2),frameon=False,ncol=3)#显示图形plt.show()2Python作图颜色汇总2.1Matplotlib颜色对照表颜色对照表来源:matplotlib颜色表-FINTHON2.2Matplotlib16进制描述颜色cnames={'aliceblue':'#F0F8FF','antiquewhite':'#FAEBD7','aqua':'#00FFFF','aquamarine':'#7FFFD4','azure':'#F0FFFF','beige':'#F5F5DC','bisque':'#FFE4C4','black':'#000000','blanchedalmond':'#FFEBCD','blue':'#0000FF','blueviolet':'#8A2BE2','brown':'#A52A2A','burlywood':'#DEB887','cadetblue':'#5F9EA0','chartreuse':'#7FFF00','chocolate':'#D2691E','coral':'#FF7F50','cornflowerblue':'#6495ED','cornsilk':'#FFF8DC','crimson':'#DC143C','cyan':'#00FFFF','darkblue':'#00008B','darkcyan':'#008B8B','darkgoldenrod':'#B8860B','darkgray':'#A9A9A9','darkgreen':'#006400','darkkhaki':'#BDB76B','darkmagenta':'#8B008B','darkolivegreen':'#556B2F','darkorange':'#FF8C00','darkorchid':'#9932CC','darkred':'#8B0000','darksalmon':'#E9967A','darkseagreen':'#8FBC8F','darkslateblue':'#483D8B','darkslategray':'#2F4F4F','darkturquoise':'#00CED1','darkviolet':'#9400D3','deeppink':'#FF1493','deepskyblue':'#00BFFF','dimgray':'#696969','dodgerblue':'#1E90FF','firebrick':'#B22222','floralwhite':'#FFFAF0','forestgreen':'#228B22','fuchsia':'#FF00FF','gainsboro':'#DCDCDC','ghostwhite':'#F8F8FF','gold':'#FFD700','goldenrod':'#DAA520','gray':'#808080','green':'#008000','greenyellow':'#ADFF2F','honeydew':'#F0FFF0','hotpink':'#FF69B4','indianred':'#CD5C5C','indigo':'#4B0082','ivory':'#FFFFF0','khaki':'#F0E68C','lavender':'#E6E6FA','lavenderblush':'#FFF0F5','lawngreen':'#7CFC00','lemonchiffon':'#FFFACD','lightblue':'#ADD8E6','lightcoral':'#F08080','lightcyan':'#E0FFFF','lightgoldenrodyellow':'#FAFAD2','lightgreen':'#90EE90','lightgray':'#D3D3D3','lightpink':'#FFB6C1','lightsalmon':'#FFA07A','lightseagreen':'#20B2AA','lightskyblue':'#87CEFA','lightslategray':'#778899','lightsteelblue':'#B0C4DE','lightyellow':'#FFFFE0','lime':'#00FF00','limegreen':'#32CD32','linen':'#FAF0E6','magenta':'#FF00FF','maroon':'#800000','mediumaquamarine':'#66CDAA','mediumblue':'#0000CD','mediumorchid':'#BA55D3','mediumpurple':'#9370DB','mediumseagreen':'#3CB371','mediumslateblue':'#7B68EE','mediumspringgreen':'#00FA9A','mediumturquoise':'#48D1CC','mediumvioletred':'#C71585','midnightblue':'#191970','mintcream':'#F5FFFA','mistyrose':'#FFE4E1','moccasin':'#FFE4B5','navajowhite':'#FFDEAD','navy':'#000080','oldlace':'#FDF5E6','olive':'#808000','olivedrab':'#6B8E23','orange':'#FFA500','orangered':'#FF4500','orchid':'#DA70D6','palegoldenrod':'#EEE8AA','palegreen':'#98FB98','paleturquoise':'#AFEEEE','palevioletred':'#DB7093','papayawhip':'#FFEFD5','peachpuff':'#FFDAB9','peru':'#CD853F','pink':'#FFC0CB','plum':'#DDA0DD','powderblue':'#B0E0E6','purple':'#800080','red':'#FF0000','rosybrown':'#BC8F8F','royalblue':'#4169E1','saddlebrown':'#8B4513','salmon':'#FA8072','sandybrown':'#FAA460','seagreen':'#2E8B57','seashell':'#FFF5EE','sienna':'#A0522D','silver':'#C0C0C0','skyblue':'#87CEEB','slateblue':'#6A5ACD','slategray':'#708090','snow':'#FFFAFA','springgreen':'#00FF7F','steelblue':'#4682B4','tan':'#D2B48C','teal':'#008080','thistle':'#D8BFD8','tomato':'#FF6347','turquoise':'#40E0D0','violet':'#EE82EE','wheat':'#F5DEB3','white':'#FFFFFF','whitesmoke':'#F5F5F5','yellow':'#FFFF00','yellowgreen':'#9ACD32'}上述16进制描述的颜色具体对应以下颜色3python中Matplotlib的颜色及线条控制3.1Matplotlib默认颜色 Matplotlib自带的颜色搭配也比较好看,默认的是一共10种颜色,超过次数后就会循环使用:默认颜色的对应参数和颜色名称如下所示:3.2Matplotlib线条控制marker参数以及形状如下所示:'.'pointmarker','pixelmarker'o'circlemarker'v'triangle_downmarker'^'triangle_upmarker''triangle_rightmarker'1'tri_downmarker'2'tri_upmarker'3'tri_leftmarker'4'tri_rightmarker's'squaremarker'p'pentagonmarker'*'starmarker'h'hexagon1marker'H'hexagon2marker'+'plusmarker'x'xmarker'D'diamondmarker'd'thin_diamondmarker'|'vlinemarker'_'hlinemarker'运行运行参考资料[1]阿昆的科研日常,跟顶刊学配色!SCI论文插图经典配色实例第1期-知乎(zhihu.com)[2]darkknightzh,(原)python中matplotlib的颜色及线条控制-darkknightzh-博客园(cnblogs.com)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 会员注册

本版积分规则

QQ|手机版|心飞设计-版权所有:微度网络信息技术服务中心 ( 鲁ICP备17032091号-12 )|网站地图

GMT+8, 2025-1-9 20:37 , Processed in 0.489254 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表