date_index_formatter
时间序列的自定义刻度格式化程序当绘制时间序列(例如,金融时间序列)时,人们经常想要省去没有数据的日子,即周末。下面的示例显示了如何使用“索引格式化程序”来实现所需的绘图。 1234567891011121314151617181920212223242526272829303132333435363738import numpy as npimport matplotlib.pyplot as pltimport matplotlib.cbook as cbookimport matplotlib.ticker as ticker# Load a numpy record array from yahoo csv data with fields date, open, close,# volume, adj_close from the mpl-data/example directory. The record array# stores the date as an np.datetime64 with a day unit ('D') in the ...
dashpointlabel
Dashpoint标签 12345678910111213141516171819202122232425262728293031323334import matplotlib.pyplot as pltDATA = ((1, 3), (2, 4), (3, 1), (4, 2))# dash_style =# direction, length, (text)rotation, dashrotation, push# (The parameters are varied to show their effects, not for visual appeal).dash_style = ( (0, 20, -15, 30, 10), (1, 30, 0, 15, 10), (0, 40, 15, 15, 10), (1, 20, 30, 60, 10))fig, ax = plt.subplots()(x, y) = zip(*DATA)ax.plot(x, y, marker='o'...
date
日期刻度标签演示如何使用日期刻度定位器和格式化程序在matplotlib中创建日期图。有关控制主要和次要刻度的更多信息,请参阅major_minor_demo1.py 所有matplotlib日期绘图都是通过将日期实例转换为自 0001-01-01 00:00:00 UTC 加上一天后的天数(由于历史原因)来完成的。 转换,刻度定位和格式化是在幕后完成的,因此这对您来说是最透明的。 日期模块提供了几个转换器函数 matplotlib.dates.date2num 和matplotlib.dates.num2date。这些可以在datetime.datetime 对象和 numpy.datetime64 对象之间进行转换。 1234567891011121314151617181920212223242526272829303132333435363738394041import numpy as npimport matplotlib.pyplot as pltimport matplotlib.dates as mdatesimport matplotlib.cbook as...
demo_annotation_box
图中插入注释框 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192import matplotlib.pyplot as pltimport numpy as npfrom matplotlib.patches import Circlefrom matplotlib.offsetbox import (TextArea, DrawingArea, OffsetImage, AnnotationBbox)from matplotlib.cbook import get_sample_dataif 1: fig, ax = plt.subplots() # Define a 1st position to an...
demo_text_path
文本路径演示使用文本作为路径。允许这种转换的工具是 TextPath。可以采用所得的路径,例如,作为图像的剪辑路径。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149import matplotlib.pyplot as pltfrom matplotlib.image import BboxImageimport numpy as npfrom matplo...
dfrac_demo
\dfrac 和 \frac之间的区别在此示例中,说明了 \dfrac和\frac TeX宏之间的差异; 特别是,使用Mathtex时显示样式和文本样式分数之间的差异。 New in version 2.1. 注意:要将 \dfrac与LaTeX引擎一起使用(text.usetex:True),您需要使用text.latex.preamble rc导入amsmath包,这是一个不受支持的功能; 因此,在 \frac宏之前使用 \displaystyle选项来获取LaTeX引擎的这种行为可能是个更好的主意。 12345678import matplotlib.pyplot as pltfig = plt.figure(figsize=(5.25, 0.75))fig.text(0.5, 0.3, r'\dfrac: $\dfrac{a}{b}$', horizontalalignment='center', verticalalignment='center')fi...
demo_text_rotation_mode
演示文本旋转模式 12345678910111213141516171819202122232425262728293031323334353637383940414243444546from mpl_toolkits.axes_grid1.axes_grid import ImageGriddef test_rotation_mode(fig, mode, subplot_location): ha_list = "left center right".split() va_list = "top center baseline bottom".split() grid = ImageGrid(fig, subplot_location, nrows_ncols=(len(va_list), len(ha_list)), share_all=True, aspect=True, # label_mode...
engineering_formatter
使用工程符号标记刻度线使用工程格式化程序。 123456789101112131415161718192021222324252627282930313233343536import matplotlib.pyplot as pltimport numpy as npfrom matplotlib.ticker import EngFormatter# Fixing random state for reproducibilityprng = np.random.RandomState(19680801)# Create artificial data to plot.# The x data span over several decades to demonstrate several SI prefixes.xs = np.logspace(1, 9, 100)ys = (0.8 + 0.4 * prng.uniform(size=100)) * np.log10(xs)**2# Figure width is doubled (2*6.4) to display nic...
fancyarrow_demo
花式箭头符号演示 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import matplotlib.patches as mpatchesimport matplotlib.pyplot as pltstyles = mpatches.ArrowStyle.get_styles()ncol = 2nrow = (len(styles) + 1) // ncolfigheight = (nrow + 0.5)fig1 = plt.figure(1, (4 * ncol / 1.5, figheight / 1.5))fontsize = 0.2 * 70ax = fig1.add_axes([0, 0, 1, 1], frameon=False, aspect=1.)ax.set_xlim(0, 4 * ncol)ax.set_ylim(0, figheight)def to_texstring(s): s = s.replace("<...
fancytextbox_demo
花式文本框演示 12345678910111213141516171819import matplotlib.pyplot as pltplt.text(0.6, 0.5, "test", size=50, rotation=30., ha="center", va="center", bbox=dict(boxstyle="round", ec=(1., 0.5, 0.5), fc=(1., 0.8, 0.8), ) )plt.text(0.5, 0.4, "test", size=50, rotation=-30., ha="right", va="top", bbox=dict(boxstyle="square", ...














