scatter_piecharts
带有饼图标记的散点图此示例将自定义 ‘饼图’ 作为散点图的标记。 感谢 Manuel Metz 的例子 1234567891011121314151617181920212223242526272829303132333435363738import numpy as npimport matplotlib.pyplot as plt# first define the ratiosr1 = 0.2 # 20%r2 = r1 + 0.4 # 40%# define some sizes of the scatter markersizes = np.array([60, 80, 120])# calculate the points of the first pie marker## these are just the origin (0,0) +# some points on a circle cos,sinx = [0] + np.cos(np.linspace(0, 2 * np.pi * r1, 10)).tolist()y = [0] + np.sin...
scatter_star_poly
星标记散点图创建多个具有不同星号符号的散点图。 12345678910111213141516171819202122232425262728293031import numpy as npimport matplotlib.pyplot as plt# Fixing random state for reproducibilitynp.random.seed(19680801)x = np.random.rand(10)y = np.random.rand(10)z = np.sqrt(x**2 + y**2)plt.subplot(321)plt.scatter(x, y, s=80, c=z, marker=">")plt.subplot(322)plt.scatter(x, y, s=80, c=z, marker=(5, 0))verts = np.array([[-1, -1], [1, -1], [1, 1], [-1, -1]])plt.subplot(323)plt.scatter(x, y, s=80, c=z, marker=ve...
scatter_with_legend
带有图例的散点图还演示了如何通过给alpha值介于0和1之间来调整标记的透明度。 12345678910111213141516import matplotlib.pyplot as pltfrom numpy.random import randfig, ax = plt.subplots()for color in ['red', 'green', 'blue']: n = 750 x, y = rand(2, n) scale = 200.0 * rand(n) ax.scatter(x, y, c=color, s=scale, label=color, alpha=0.3, edgecolors='none')ax.legend()ax.grid(True)plt.show() 下载这个示例 下载python源码: scatter_with_legend.py 下载Jupyter notebook: scatter_with_legen...
scatter_symbol
三叶草样式的散点图用三叶草符号表示散点图。 1234567891011121314151617import matplotlib.pyplot as pltimport numpy as np# Fixing random state for reproducibilitynp.random.seed(19680801)x = np.arange(0.0, 50.0, 2.0)y = x ** 1.3 + np.random.rand(*x.shape) * 30.0s = np.random.rand(*x.shape) * 800 + 500plt.scatter(x, y, s, c="g", alpha=0.5, marker=r'$\clubsuit$', label="Luck")plt.xlabel("Leprechauns")plt.ylabel("Gold")plt.legend(loc='upper left')plt...
simple_plot
简单图例创建一个简单的图。 1234567891011121314151617import matplotlibimport matplotlib.pyplot as pltimport numpy as np# Data for plottingt = np.arange(0.0, 2.0, 0.01)s = 1 + np.sin(2 * np.pi * t)fig, ax = plt.subplots()ax.plot(t, s)ax.set(xlabel='time (s)', ylabel='voltage (mV)', title='About as simple as it gets, folks')ax.grid()fig.savefig("test.png")plt.show() 参考下面的示例演示了以下函数和方法的使用: 1234matplotlib.axes.Axes.plotmatplotlib.pyplot.plotmatplotlib.pyplot.subpl...
span_regions
使用span_where说明一些用于逻辑掩码为True的阴影区域的辅助函数。 请参考 matplotlib.collections.BrokenBarHCollection.span_where() 12345678910111213141516171819202122232425import numpy as npimport matplotlib.pyplot as pltimport matplotlib.collections as collectionst = np.arange(0.0, 2, 0.01)s1 = np.sin(2*np.pi*t)s2 = 1.2*np.sin(4*np.pi*t)fig, ax = plt.subplots()ax.set_title('using span_where')ax.plot(t, s1, color='black')ax.axhline(0, color='black', lw=2)collection = collections.BrokenBarHColl...
stackplot_demo
堆栈图示例如何使用Matplotlib创建堆栈图。 通过将不同的数据集垂直地绘制在彼此之上而不是彼此重叠来生成堆积图。下面我们展示一些使用Matplotlib实现此目的的示例。 1234567891011121314151617181920import numpy as npimport matplotlib.pyplot as pltx = [1, 2, 3, 4, 5]y1 = [1, 1, 2, 3, 5]y2 = [0, 4, 2, 6, 8]y3 = [1, 3, 5, 7, 9]y = np.vstack([y1, y2, y3])labels = ["Fibonacci ", "Evens", "Odds"]fig, ax = plt.subplots()ax.stackplot(x, y1, y2, y3, labels=labels)ax.legend(loc='upper left')plt.show()fig, ax = plt.subplots()ax.stackplot(x,...
spectrum_demo
频谱表示图该图显示了具有加性噪声的正弦信号的不同频谱表示。 通过利用快速傅立叶变换(FFT)计算离散时间信号的(频率)频谱。 12345678910111213141516171819202122232425262728293031323334353637383940414243import matplotlib.pyplot as pltimport numpy as npnp.random.seed(0)dt = 0.01 # sampling intervalFs = 1 / dt # sampling frequencyt = np.arange(0, 10, dt)# generate noise:nse = np.random.randn(len(t))r = np.exp(-t / 0.05)cnse = np.convolve(nse, r) * dtcnse = cnse[:len(t)]s = 0.1 * np.sin(4 * np.pi * t) + cnse # the signalfig, axes = plt.subplots(nrows=3,...
stem_plot
茎状图示茎图的绘制是从基线到y坐标的垂直线绘制cosine(x) w.r.t x,使用 ‘-.’ 作为绘制垂直线的图案。 123456789101112import matplotlib.pyplot as pltimport numpy as np# returns 10 evenly spaced samples from 0.1 to 2*PIx = np.linspace(0.1, 2 * np.pi, 10)markerline, stemlines, baseline = plt.stem(x, np.cos(x), '-.')# setting property of baseline with color red and linewidth 2plt.setp(baseline, color='r', linewidth=2)plt.show() 此示例使用了: * matplotlib.axes.Axes.stem() 下载这个示例 下载python源码: stem_plot.py 下载Jupyter notebook...
timeline
使用线、日期、文本创建时间轴图如何使用Matplotlib发布日期创建简单的时间轴。 可以使用日期和文本的集合创建时间轴。在本例中,我们将展示如何使用Matplotlib最新版本的日期创建一个简单的时间轴。首先,我们将从GitHub中提取数据。 123456789101112131415161718192021import matplotlib.pyplot as pltimport numpy as npimport matplotlib.dates as mdatesfrom datetime import datetime# A list of Matplotlib releases and their dates# Taken from https://api.github.com/repos/matplotlib/matplotlib/releasesnames = ['v2.2.2', 'v2.2.1', 'v2.2.0', 'v2.1.2', 'v2.1.1', ...














