style

1.绘制x=1

2.不同线宽

  • enumerate(Widths)

    3.线型(实线,虚线,点划线)
  • linestyle
  • set_dashes

    4.自动设置线颜色

    5.点的显示形式
  • marker
  • markersize
  • markeredgecolor
  • markerfacecolor

    6.柱状图及其填充
  • axes.bar
  • axes.bar( .5+i, 1, hatch='/', color='white', edgecolor='blue',)

x=1

code

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib
import matplotlib.pyplot as plt #Data
Y=np.linspace(0,1,12)
X=np.ones(Y.size) #figure
fig = plt.figure(figsize=(8,6), dpi=72, facecolor='white')
axes = plt.subplot(111) #plot
axes.plot( (1+0)*X, Y, linewidth=0.25, color='blue') plt.show()

Keypoints

axes.plot( (1+0)*X, Y, linewidth=0.25, color='blue')

X=[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]

Y=[ 0. 0.09090909 0.18181818 0.27272727 0.36363636 0.45454545

0.54545455 0.63636364 0.72727273 0.81818182 0.90909091 1. ]

Result


不同线宽

code

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib
import matplotlib.pyplot as plt # Data to be represented
Y = np.linspace(0,1,12)
print Y X = np.ones(Y.size)
print X W = [0.25,0.50,0.75,1,2,3,4,5,6,7,8] #linewidth
print W # Actual plotting
fig = plt.figure(figsize=(8,6), dpi=72, facecolor='white')
axes = plt.subplot(111) for i,w in enumerate(W):
axes.plot( (1+i)*X, Y, linewidth=w, color='blue') # X,Y axes lable
axes.set_xlim(0,len(W)+1)
axes.set_yticks([])
axes.set_xticks(np.arange(1,len(W)+1))
axes.set_xticklabels(['%.2f' % w for w in W]) plt.show()

Keypoints

for i,w in enumerate(W):

axes.plot( (1+i)*X, Y, linewidth=w, color='blue')


![enumerate-help.png](https://raw.githubusercontent.com/urmyfaith/urmyfaith.github.io/master/matplot/matplotGallery/images/enumerate-help.png) 绘制12条直线,X=1,...X=12 ### Result ![style-02.png](https://raw.githubusercontent.com/urmyfaith/urmyfaith.github.io/master/matplot/matplotGallery/images/style-02.png) 隐藏Y轴刻度,替换X轴标签后的图形 ![style-03.png](https://raw.githubusercontent.com/urmyfaith/urmyfaith.github.io/master/matplot/matplotGallery/images/style-03.png) ---- ## 线型(实线,虚线,点划线) ### code ```python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib
import matplotlib.pyplot as plt # Data to be represented
X = np.linspace(0,1,10)
Y = np.ones(X.size) # Actual plotting
fig = plt.figure(figsize=(8,6), dpi=72, facecolor="white")
axes = plt.subplot(111,aspect=1)
axes.plot( X, Y*0.1, color = 'blue', linewidth=2, linestyle="-" )
axes.plot( X, Y*0.2, color = 'blue', linewidth=2, linestyle="--" )
axes.plot( X, Y*0.3, color = 'blue', linewidth=2, linestyle="-." )
axes.plot( X, Y*0.4, color = 'blue', linewidth=2, linestyle=":" )
line, = axes.plot( X, Y*0.5, color = 'blue', linewidth=2, linestyle="-" )
line.set_dashes([20,2])
line, = axes.plot( X, Y*0.6, color = 'blue', linewidth=2, linestyle="-" )
line.set_dashes([2,20])
line, = axes.plot( X, Y*0.7, color = 'blue', linewidth=2, linestyle="-" )
line.set_dashes((40,5,5,5))
line, = axes.plot( X, Y*0.8, color = 'blue', linewidth=2, linestyle="-" )
line.set_dashes((40,5,5,5,5,5))
line, = axes.plot( X, Y*0.9, color = 'blue', linewidth=2, linestyle="-" )
line.set_dashes((40,5,5,5,5,5,40,5)) axes.set_xlim(X.min(),X.max())
axes.set_ylim(0,1)
axes.set_xticks([])
axes.set_yticks(np.arange(1,10)/10.0)
axes.set_yticklabels(("-","--","-.",":",
"(20,2)", "(2,20)", "(40,5,5,5)",
"(40,5,5,5,5,5,5)", "(40,5,5,5,5,40)"))
plt.show()

Keypoints

axes.plot( X, Y*0.1, color = 'blue', linewidth=2, linestyle="-")

linestyle="-" 线型:

  • --
  • -.
  • :

控制点划线的点,空格,划的长度:

line, = axes.plot( X, Y*0.9, color = 'blue', linewidth=2, linestyle="-" )
line.set_dashes((40,5,5,5,5,5,40,5))

40划5空格5点5空格5点5空格40划5空格

Result


自动设置线颜色

code

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib
import matplotlib.pyplot as plt # Data to be represented
Y = np.linspace(0,1,12)
X = np.ones(Y.size) # Actual plotting
fig = plt.figure(figsize=(8,6), dpi=72, facecolor="white")
axes = plt.subplot(111) lineNumbers=9
for i in range(lineNumbers):
axes.plot( (1+i)*X, Y, linewidth=4) axes.set_xlim(0,lineNumbers+1)
axes.set_yticks([])
axes.set_xticks(np.arange(1,lineNumbers+1)) plt.show()

Keypoints

这里用循环绘制了9条直线,但是这里是自动填充颜色的?

Result


5. 点的显示形式

code

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib
import matplotlib.pyplot as plt # Data to be represented
Y = np.linspace(0,1,12)
X = np.ones(Y.size)
markers = ['.',',','o','v','^','<','>','1','2','3','4',
's','p','*','h','H','+','x','D','d','|','_', r'$\clubsuit$'] # Actual plotting
fig = plt.figure(figsize=(8,6), dpi=72, facecolor="white")
axes = plt.subplot(111)
for i,marker in enumerate(markers):
axes.plot( (1+i)*X, Y, color = '0.9', linewidth=1,
markersize = 13, marker=marker,
markeredgecolor = '0.10', markerfacecolor = '0.75') axes.set_xlim(0,len(markers)+1)
axes.set_ylim(Y.min(),Y.max())
axes.set_yticks([])
axes.set_xticks(np.arange(1,len(markers)+1))
axes.set_xticklabels(markers) plt.show()

Keypoints

   axes.plot( (1+i)*X, Y, color = '0.9', linewidth=1,
markersize = 13, marker='x',
markeredgecolor = '0.10', markerfacecolor = '0.75')

标记的大小,类型,边缘颜色,前景色

Resutl


6. 柱状图及其填充

code

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib
import matplotlib.pyplot as plt # Data to be represented
X = np.linspace(0,1,10)
Y = np.ones(X.size)
patterns = ('/','//','-', '+', 'x', '\\', '\\\\', '*', 'o', 'O', '.') # Actual plotting
fig = plt.figure(figsize=(8,6), dpi=72, facecolor="white")
axes = plt.subplot(111)
for i,pattern in enumerate(patterns):
axes.bar( .5+i, 1, hatch=pattern, color='white', edgecolor='blue',) axes.set_xlim(0,len(patterns)+.5)
axes.set_ylim(0,1) axes.set_yticks([])
axes.set_xticks(np.arange(1,len(patterns)+1))
axes.set_xticklabels(patterns) plt.show()

Keypoints

axes.bar( .5+i, 1, hatch=pattern, color='white', edgecolor='blue',)



hatch,柱状图的填充:

Result

matplotlib-plot-style的更多相关文章

  1. python matplotlib plot 数据中的中文无法正常显示的解决办法

    转发自:http://blog.csdn.net/laoyaotask/article/details/22117745?utm_source=tuicool python matplotlib pl ...

  2. python matplotlib.plot画图显示中文乱码的问题

    在matplotlib.plot生成的统计图表中,中文总是无法正常显示.在网上也找了些资料,说是在程序中指定字体文件,不过那样的话需要对plot进行很多设置,而且都是说的设置坐标轴标题为中文,有时候图 ...

  3. 用Python设置matplotlib.plot的坐标轴刻度间隔以及刻度范围

    一.用默认设置绘制折线图 import matplotlib.pyplot as plt x_values=list(range(11)) #x轴的数字是0到10这11个整数 y_values=[x* ...

  4. matplotlib 可视化 —— style sheets

    Customizing plots with style sheets Matplotlib Style Gallery 1. 常见 style ggplot: bmh:Bayesian Method ...

  5. matplotlib plot 绘图函数发生阻塞(block)时的解决方法

    Is there a way to detach matplotlib plots so that the computation can continue? 在一般编辑器中: from matplo ...

  6. Python Matplotlib.plot Update image Questions

    1. 最近在测试一款设备,采集了一些设备后需要一帧一帧显示图像,经常使用Python,所以选用了Matplotlib进行图像操作 数据结构: timesatamp polar_distance hor ...

  7. 05. Matplotlib 1 |图表基本元素| 样式参数| 刻度 注释| 子图

    1.Matplotlib简介及图表窗口 Matplotlib → 一个python版的matlab绘图接口,以2D为主,支持python.numpy.pandas基本数据结构,运营高效且有较丰富的图表 ...

  8. python时间序列画图plot总结

    画图从直觉上来讲就是为了更加清晰的展示时序数据所呈现的规律(包括趋势,随时间变化的规律(一周.一个月.一年等等)和周期性规律),对于进一步选择时序分析模型至关重要.下面主要是基于pandas库总结一下 ...

  9. matplotlib 画图

    matplotlib 画图 1. 画曲线图       Tompson = np.array([0, 0, 0, 0, 0.011, 0.051, 0.15, 0.251, 0.35, 0.44, 0 ...

  10. 学机器学习,不会数据分析怎么行——数据可视化分析(matplotlib)

    前言 前面两篇文章介绍了 python 中两大模块 pandas 和 numpy 的一些基本使用方法,然而,仅仅会处理数据还是不够的,我们需要学会怎么分析,毫无疑问,利用图表对数据进行分析是最容易的, ...

随机推荐

  1. 在windows下安装Jupyter Notebook的安装和使用

    1 认识jupyter jupyter /ˈdʒuːpɪtə(r)/可以提供适合捕捉整个计算过程的基于web的应用程序:开发.记录和执行代码,以及结果输出. jupyter Notebook提供了两个 ...

  2. Eclipse配置SQL Explorer插件和数据库

    1.下载SQL Explore插件,地址:http://www.sqlexplorer.org/,下载第三个.复制到eclipse插件相应文件夹重新启动,下载RCP插件能够直接使用exe 2.下载JD ...

  3. Java与C++Socket通讯注意事项

    c++与java进行socket通信时注意事项 原文链接: http://my.oschina.net/ypimgt/blog/106439 因为java发送的都是网络字节序(big-endium), ...

  4. MFC添加自定义窗口消息

    原文链接: http://www.cnblogs.com/smartvessel/archive/2011/07/18/2109472.html 1. 在头文件stdafx.h中增加一个自定义消息宏 ...

  5. 第一篇:初识ASP.NET控件开发_第一节:控件类及其继承关系

    1)System.Web.UI.Control(以下简称Control) Control 类是包括自定义控件.用户控件和页在内的所有 ASP.NET 服务器控件的基类..定义由所有 ASP.NET 服 ...

  6. 活久见: 原来 Chrome 浏览器支持 Import from 语法

    需要满足以下三个条件: 1.高版本的Chrome ,总而言之越新越好……,其他浏览器请参考:https://caniuse.com/#search=import 2.必须在服务器环境下才能运行,譬如a ...

  7. Knockout: 让ViewModel从htm中剥离出去。

    在一些Knockout例子中,直接在htm中添加scripts写viewmodel,如何能将让ViewModel从htm中剥离出去呢?从knockout官网上找到了解决方法,如下: 1.knockou ...

  8. jquery判断选择元素是否存在

    有时候我们需要对jquery选择器选中的元素进行判断是否存在,如果存在才进行某些操作,不存在就不进行,那么如何判断元素是否存在,代码如下: //判断是否存在特定ID值的元素 ){ alert(&quo ...

  9. Centos 二进制安装node.js

    一.登录node的官网查看最新的稳定版,以及需要下载的Linux版本,你可以有多种Linux安装方式(源码安装,二进制安装等). 二.Node安装及配置 1.创建安装目录:创建目录node.js [r ...

  10. python 保留两位小数

    >>> a = 1 >>> b = 3 >>> print(a/b) 0 >>> #方法一: ... print(round(a ...