matplotlib
文章平均质量分 53
python第三方绘图库
千行百行
这个作者很懒,什么都没留下…
展开
-
matplotlib中线宽linewidth的默认值是多少?如何查看?如何设置/设定?如何修改?
文章目录绘图读取线宽修改线宽see also绘图使用下边的代码绘图:import numpy as npimport matplotlib.pyplot as pltx = np.arange(0.0, 2.0, 0.02)y1 = np.sin(2 * np.pi * x)y2 = np.exp(-x)line1, = plt.plot(x, y1)line2, = plt.plot(x, y2)绘制结果如下图所示:读取线宽使用下边的代码,读取线宽linewidth的默认值,发原创 2021-11-10 16:36:50 · 6430 阅读 · 0 评论 -
使用matplotlib绘图添加标题title时出现TypeError: ‘Text‘ object is not callable,这么改就对了
文章目录错误复现报错解决办法plt.title和ax.set_titlesee also错误复现import matplotlib.pyplot as pltimport numpy as npimport mathx = np.arange(1000)y = np.sin(2*math.pi*x/1000)fig, ax = plt.subplots()ax.plot(x, y)ax.title("sine") # 报错:TypeError: 'Text' object is no原创 2021-10-17 22:09:17 · 7786 阅读 · 0 评论 -
【Matplotlib系列】绘制折线图时横轴太长,如何选中部分区域进行放大?不妨试试matplotlib的高级交互功能Span Selector
文章目录适用场合代码效果拓展Reference适用场合折线图横轴太长的场合。或者举一个更具体的例子,如果绘制一只股票十年以来每天的收盘价,那么大概有2500条数据,横轴跨度很大,如果只想看一部分时段的数据,就可以用到Span Selector。用了这个功能你就不需要不停地选择数据,不停地plt.plot了。可以大大提高效率。代码import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.widgets import SpanS原创 2021-08-07 21:24:51 · 2379 阅读 · 1 评论 -
【官方教你】提高效率超30倍!matplotlib绘制散点图plt.scatter太慢了!
代码see alsomatplotlib官方cheatsheets(GitHub链接)截图如下:吐槽既然plot这么强,为什么不把scatter搞得强一点呢?希望matplotlib再接再厉!原创 2021-07-08 20:28:53 · 5998 阅读 · 0 评论 -
Matplotlib系列cheatsheet(一):刻度线tick和标签labels
# ----------------------------------------------------------------------------# Title: Scientific Visualisation - Python & Matplotlib# Author: Nicolas P. Rougier# License: BSD# --------------------------------------------------------------------原创 2021-04-10 21:57:59 · 401 阅读 · 0 评论 -
python matplotlib 绘制双Y轴曲线图,两个坐标轴的刻度不同、比例不同
import numpy as npimport matplotlib.pyplot as plt# 创建模拟数据t = np.arange(0.01, 10.0, 0.01)data1 = np.exp(t)data2 = np.sin(2 * np.pi * t)fig, ax1 = plt.subplots()color = 'tab:red'ax1.set_xlabel('time (s)')ax1.set_ylabel('exp', color=color)ax1.plo原创 2021-03-18 20:33:43 · 16100 阅读 · 0 评论 -
AttributeError: ‘AxesSubplot‘ object has no attribute ‘ylabel‘,matplotlib报错
解决bug原创 2021-03-12 11:51:49 · 9504 阅读 · 3 评论 -
python使用matplotlib的plt.subplot、plt.subplots绘制多图以及图例legend注意事项
一个图片里边绘制多个图像是绘图中的常见需求。下边介绍几种实现方法,然后简单分析一下他们的细微区别,并说明了添加legend时候常见的一些坑。原创 2021-03-10 20:16:26 · 7581 阅读 · 2 评论 -
python之matplotlib 3.2.1生成指定尺寸大小指定dpi的图片
直接上代码import matplotlib.pyplot as pltfig_width = 16/2.54 # 宽度16cmfig_height = 8/2.54 # 高度8cmdpi = 300 # 指定保存的dpi用于保存图片时候使用fig, ax = plt.subplots( nrows=1, ncols=1, figsize=(fig_widt...原创 2020-04-20 15:07:36 · 5120 阅读 · 0 评论 -
python之matplotlib 3.2.1之坐标轴上下限设置
plt.版本参照matplotlib官方指南,里边的第一个例子值得参考。具体操作如下:plt.xlim(-5, 5)plt.ylim(-5, 5)axes.版本参照matplotlib官方示例,具体操作如下:ax.set_xlim(x_min, x_max)ax.set_ylim(y_min, y_max)...原创 2020-04-20 14:54:43 · 4206 阅读 · 0 评论 -
python之matplotlib 3.2.1之坐标轴刻度(坐标轴标签)字号、字体设置
如图所示坐标轴刻度在matplotlib中被称为tick label,因此准确来说,坐标轴刻度应该称之为坐标轴标签。修改坐标轴刻度的字号操作相对来说比较简单:font_size = 10ax.tick_params(labelsize=font_size)修改坐标轴刻度的字体操作相对来说比较麻烦:labels = axes[0].get_xticklabels() + axes[0...原创 2020-04-20 14:07:04 · 6088 阅读 · 2 评论 -
python之matplotlib 3.2.1之legend之图例位置、字体和框线设置
用一个例子展开说明:legend_font = { 'family': 'Arial', # 字体 'style': 'normal', 'size': font_size, # 字号 'weight': "normal", # 是否加粗,不加粗}ax.legend( bbox_to_anchor=(0.5, 0.95), loc='lo...原创 2020-04-19 21:52:51 · 11963 阅读 · 0 评论 -
python之matplotlib 3.2.1之spines不显示右侧和顶端的坐标轴
不显示右侧和顶端的坐标轴是通过spines实现的,具体操作如下:# 隐藏右侧和顶端的坐标轴ax.spines['right'].set_visible(False)ax.spines['top'].set_visible(False)可以参照matplotlib官方文档之Ticks and spines下边的例子进行操作。...原创 2020-04-19 17:39:09 · 4525 阅读 · 0 评论 -
python之matplotlib 3.2.1 字体设置
字体有以下6个属性:1family:字体,如:‘serif’、'sans-serif’等。需要注意的是,虽然支持’Times New Roman’但是存在一个bug:使用Times New Roman时候字体只能是加粗的,weight属性失效2,但是使用其他字体时可以通过weight属性来控制加粗还是不加粗。stylevariantstretchweightsizematp...原创 2020-04-17 22:35:43 · 334 阅读 · 0 评论