python中matplotlib的颜色及线条控制

参考网址:

http://stackoverflow.com/questions/22408237/named-colors-in-matplotlib

http://stackoverflow.com/questions/8409095/matplotlib-set-markers-for-individual-points-on-a-line

代码:

plt.subplots(1, 1)
x= range(100)
y= [i**2 for i in x]

plt.plot(x, y, linewidth = ‘1‘, label = "test", color=‘ coral ‘, linestyle=‘:‘, marker=‘|‘)
plt.legend(loc=‘upper left‘)
plt.show()

结果:

说明:其实上面color=‘ coral ‘中,可以换成color=‘ #054E9F‘,每两个十六进制数分别代表R、G、B分量:

第二个参考网址给出了linestyle可选参数:

‘-‘       solid line style
‘--‘      dashed line style
‘-.‘      dash-dot line style
‘:‘       dotted line style

第二个参考网址给出了marker可选参数:

‘.‘       point marker
‘,‘       pixel marker
‘o‘       circle marker
‘v‘       triangle_down marker
‘^‘       triangle_up marker
‘<‘       triangle_left marker
‘>‘       triangle_right marker
‘1‘       tri_down marker
‘2‘       tri_up marker
‘3‘       tri_left marker
‘4‘       tri_right marker
‘s‘       square marker
‘p‘       pentagon marker
‘*‘       star marker
‘h‘       hexagon1 marker
‘H‘       hexagon2 marker
‘+‘       plus marker
‘x‘       x marker
‘D‘       diamond marker
‘d‘       thin_diamond marker
‘|‘       vline marker
‘_‘       hline marker

第一个参考网址给出了matplotlib中color可用的颜色:

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‘}

上面对应的颜色:

另外的显示方式:

装了seaborn扩展的话,在字典seaborn.xkcd_rgb中包含所有的xkcd crowdsourced color names。如下:

plt.plot([1,2], lw=4, c=seaborn.xkcd_rgb[‘baby poop green‘])

所有颜色如下:

标签: python

时间: 2024-10-01 02:37:41

python中matplotlib的颜色及线条控制的相关文章

python中matplotlib实现最小二乘法拟合的过程详解

这篇文章主要给大家介绍了关于python中matplotlib实现最小二乘法拟合的相关资料,文中通过示例代码详细介绍了关于最小二乘法拟合直线和最小二乘法拟合曲线的实现过程,需要的朋友可以参考借鉴,下面来一起看看吧. 前言 最小二乘法Least Square Method,做为分类回归算法的基础,有着悠久的历史(由马里·勒让德于1806年提出).它通过最小化误差的平方和寻找数据的最佳函数匹配.利用最小二乘法可以简便地求得未知的数据,并使得这些求得的数据与实际数据之间误差的平方和为最小.最小二乘法还

python中matplotlib画折线图实例(坐标轴数字、字符串混搭及标题中文显示)

最近在用python中的matplotlib画折线图,遇到了坐标轴 "数字+刻度" 混合显示.标题中文显示.批量处理等诸多问题.通过学习解决了,来记录下.如有错误或不足之处,望请指正. 一.最简单的基本框架如下:已知x,y,画出折线图并保存.此时x和y均为数字. 1 # -*- coding: utf-8 -*- 2 3 import matplotlib.pyplot as plt #引入matplotlib的pyplot子库,用于画简单的2D图 4 import random 5

Python中matplotlib模块解析

用Matplotlib绘制二维图像的最简单方法是: 1.  导入模块 导入matplotlib的子模块 import matplotlib.pyplot as plt import numpy as np 2.  获取数据对象 给出x,y两个数组[Python列表],注意两个列表的元素个数必须相同,否则会报错 x=np.array([1,2,3,4,]) y=x*2 3.  调用画图方法 调用pyplot模块的绘图方法画出图像,基本的画图方法有:plot(将各个点连成曲线图).scatter(画

python中matplotlib绘图封装类之折线图、条状图、圆饼图

DrawHelper.py封装类源码: 1 import matplotlib 2 import matplotlib.pyplot as plt 3 import numpy as np 4 5 class DrawHelper: 6 def __init__(self): 7 # 指定默认字体 下面三条代码用来解决绘图中出现的乱码 8 matplotlib.rcParams['font.sans-serif'] = ['SimHei'] 9 matplotlib.rcParams['font

python中print输出带颜色的方法详解

书写格式 开头部分:\033[显示方式;前景色;背景色m + 结尾部分:\033[0m ? 注意:开头部分的三个参数:显示方式,前景色,背景色是可选参数,可以只写其中的某一个:另外由于表示三个参数不同含义的数值都是唯一的没有重复的,所以三个参数的书写先后顺序没有固定要求,系统都能识别:但是,建议按照默认的格式规范书写. ? 对于结尾部分,其实也可以省略,但是为了书写规范,建议\033[***开头,\033[0m结尾. 颜色简介 ----------------------------------

Python中matplotlib模块的简单使用

测试代码如下: 1 # encoding:utf-8 2 import numpy as np 3 import matplotlib.pyplot as plt 4 x = np.array([1,2,3,4,5,6,7,8]) 5 y = np.array([3,5,7,6,2,6,10,15]) 6 plt.plot(x,y,'r')# 折线 1 x 2 y 3 color 7 plt.plot(x,y,'g',lw=10)# 4 line w 8 # 折线 饼状 柱状 9 x = np.

python中matplotlib画图

参考 https://blog.csdn.net/u010358304/article/details/78906768 https://www.cnblogs.com/onemorepoint/p/7482644.html https://www.cnblogs.com/onemorepoint/p/7481643.html 原文地址:https://www.cnblogs.com/yqpy/p/10074095.html

python中输出带有颜色的字体

参考内容:https://www.cnblogs.com/daofaziran/p/9015284.html,感谢博主:老虎死了还有狼,若有侵权行为,请通知本人,会立马删除,谢谢: 格式: 开始部分:\033[显示方式;前景色;背景色m + 结束部分:\033[0m 原文地址:https://www.cnblogs.com/learning-python/p/10208093.html

python可视化——matplotlib画图颜色控制

https://blog.csdn.net/CD_Don/article/details/88070453?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1 原文地址:https://www.cnblogs.com/zb-ml/p/1269334