详细内容参看:官网


测试数据:

# 传入的参数
x=[1,2,3,4,5]
squares=[1,4,9,16,25]

简单的绘图

import matplotlib.pyplot as plt

def plot1(x,squares):
"""plot simple pic""" plt.plot(x,squares,linewidth=1)
# or plt.plot(squares) plt.show()
  • plt.plot(x,y)
  • plt.show()

改变文字、字体、线宽

def plot2(x,squares):
"""change literature and line width"""
plt.plot(x,squares,linewidth=2) plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14) # set labelsize of x, y
plt.tick_params(axis='both',labelsize=14) plt.show()
  • plt.title("title")
  • plt.xlabel('xlabel')
  • plt.ylabel('ylabel')
  • plt.tick_params(axis,labelsize)

自动生成数据

def plot3():
"""automatically compute the data"""
x_val = list(range(1,1001))
y_val = [x**2 for x in x_val] plt.scatter(x_val,y_val,s=5) plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14) # set labelsize of x, y
plt.tick_params(axis='both',labelsize=14) plt.axis([0,1100,0,1100000]) plt.show()
  • plt.axis([0,1100,0,110000])
  • plt.scatter(x,y,s)

颜色改变(很漂亮)

def plot4():
"""change the color"""
x_val = list(range(1,1001))
y_val = [x**2 for x in x_val] # delete the default edgecolor(black)
# change color by adjusting c
plt.scatter(x_val,y_val,edgecolor='none',c=(0.5,0.6,0.3),s=5) plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14) # set labelsize of x, y
plt.tick_params(axis='both',labelsize=14) plt.axis([0,1100,0,1100000]) plt.show()
  • plt.scatter(x,y,edgecolor='none',c,s)

    • c用来调节颜色
    • s代表size
def plot5():
"""using colormap"""
x_val = list(range(1,1001))
y_val = [x**2 for x in x_val] # delete the default edgecolor(black)
# using cmap to make gradient
plt.scatter(x_val,y_val,edgecolor='none',c=y_val,s=5,cmap=plt.cm.Blues) plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14) # set labelsize of x, y
plt.tick_params(axis='both',labelsize=14) plt.axis([0,1100,0,1100000]) plt.show()
  • plt.scatter(x,y,edgecolor,c,s,cmap)

    • cmap颜色映射

      • plt.cm.Blues
      • plt.cm.Reds
      • plt.cm.Greens
      • plt.cm.Paired
      • plt.cm.binary
      • plt.cm.seismic

保存图片

def plot6():
"""using colormap"""
x_val = list(range(1,1001))
y_val = [x**2 for x in x_val] # delete the default edgecolor(black)
# using cmap to make gradient
# cmap(plt.cm.*) Blues Reds Greens Paired binary seismic
plt.scatter(x_val,y_val,edgecolor='none',c=y_val,s=5,cmap=plt.cm.seismic) plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14) # set labelsize of x, y
plt.tick_params(axis='both',labelsize=14) plt.axis([0,1100,0,1100000]) # do not show, save it
plt.savefig('save.png',bbox_inches='tight')
  • plt.savefig('name.jpg',bbox_inches)

    • 一般bbox_inches='tight'比较好

python应用-matplotlib绘图的更多相关文章

  1. python 中matplotlib 绘图

    python 中matplotlib 绘图 数学建模需要,对于绘图进行简单学习 matpoltlib之类的包安装建议之间用anaconda 绘制一条y=x^2的曲线 #比如我们要绘制一条y=x^2的曲 ...

  2. python之matplotlib绘图基础

    Python之matplotlib基础 matplotlib是Python优秀的数据可视化第三方库 matplotlib库的效果可参考 http://matplotlib.org/gallery.ht ...

  3. python基于matplotlib绘图

    import math import numpy as np import matplotlib.pyplot as plt from matplotlib.font_manager import F ...

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

    DrawHelper.py封装类源码: import matplotlib import matplotlib.pyplot as plt import numpy as np class DrawH ...

  5. Python用matplotlib绘图网格线的设置

    一.X轴网格线的设置 import matplotlib.pyplot as plt import numpy as np from pylab import mpl mpl.rcParams['fo ...

  6. python中利用matplotlib绘图可视化知识归纳

    python中利用matplotlib绘图可视化知识归纳: (1)matplotlib图标正常显示中文 import matplotlib.pyplot as plt plt.rcParams['fo ...

  7. python 利用matplotlib中imshow()函数绘图

    matplotlib 是python最著名的2D绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中.通过简单的绘图语 ...

  8. python实战学习之matplotlib绘图

    matplotlib 是最流行的Python底层绘图库,主要做数据可视化图表 可以将数据可视化,能够更直观的呈现数据 matplotlib绘图基本要点 首先实现一个简单的绘图 # 导入pyplot f ...

  9. python强大的绘图模块matplotlib示例讲解

    Matplotlib 是 Python 的绘图库.作为程序员,经常需要进行绘图,在我自己的工作中,如果需要绘图,一般都是将数据导入到excel中,然后通过excel生成图表,这样操作起来还是比较繁琐的 ...

随机推荐

  1. Windows Phone 有关独立存储(一)

    private const string foldername = "temp1"; private const string filename = foldername + &q ...

  2. Android 动态设置控件高度

    TextView textView= (TextView)findViewById(R.id.textview); LinearLayout.LayoutParams linearParams =(L ...

  3. List<String>和String相互转换

    List<String>转String String Message=""; for (String msg : message) { Message = Messag ...

  4. OC开发_Storyboard——多线程、UIScrollView

    一.多线程 1.主队列:处理多点触控和所有UI操作(不能阻塞.主要同步更新UI) dispatch_queue_t mainQueue = dispatchg_get_main_queue(); // ...

  5. C /C ++中结构体的定义

    c语言中结构体的定义: struct 结构体名{ 成员列表: ..... }结构体变量: 7.1.1 结构体类型变量的定义结构体类型变量的定义与其它类型的变量的定义是一样的,但由于结构体类型需要针对问 ...

  6. Redis构建处理海量数据的大型购物网站

    本系列教程内容提要 Java工程师之Redis实战系列教程教程是一个学习教程,是关于Java工程师的Redis知识的实战系列教程,本系列教程均以解决特定问题为目标,使用Redis快速解决在实际生产中的 ...

  7. nginx解决带_的head内容丢失

    若请求 Head 信息中存在自定义信息并且以 "_" 下划线间隔,则必须配置underscores_in_headers 否则 Head 无法向 Tomcat 转发 解决办法: 在 ...

  8. Lucene.net之解决锁的问题

    public sealed class SearchIndexManager { private static readonly SearchIndexManager searchManager=ne ...

  9. js 格式验证大全

    1.身份证号码验证: var Common = { //身份证号验证 IsIdCardNo: function (IdCard) { var reg = /^\d{15}(\d{2}[0-9X])?$ ...

  10. Grafana+Prometheus监控

    添加模板一定要看说明以及依赖 监控redis https://blog.52itstyle.com/archives/2049/ http://www.cnblogs.com/sfnz/p/65669 ...