date_demo_rrule
演示日期Rrule展示如何使用Rrule实例制作自定义日期自动收报机 - 这里我们在每5个复活节放置一个刻度线。 有关Rrules的帮助,请参阅https://dateutil.readthedocs.io/en/stable/ 1234567891011121314151617181920212223242526272829import matplotlib.pyplot as pltfrom matplotlib.dates import (YEARLY, DateFormatter, rrulewrapper, RRuleLocator, drange)import numpy as npimport datetime# Fixing random state for reproducibilitynp.random.seed(19680801)# tick every 5th easterrule = rrulewrapper(YEARLY, byeaster=1, interval=5)loc = RRuleL...
date_index_formatter2
日期索引格式化程序在绘制每日数据时,频繁的请求是绘制忽略跳过的数据,例如,周末没有额外的空格。这在金融时间序列中尤为常见,因为您可能拥有M-F而非Sat,Sun的数据,并且您不需要x轴上的间隙。方法是简单地使用xdata的整数索引和自定义刻度Formatter来获取给定索引的适当日期字符串。 输出: 1loading /home/tcaswell/mc3/envs/dd37/lib/python3.7/site-packages/matplotlib/mpl-data/sample_data/msft.csv 12345678910111213141516171819202122232425262728293031323334import numpy as npimport matplotlib.pyplot as pltimport matplotlib.cbook as cbookfrom matplotlib.dates import bytespdate2num, num2datefrom matplotlib.ticker import Formatterdataf...
date_demo_convert
演示日期转换 12345678910111213141516171819202122232425262728293031import datetimeimport matplotlib.pyplot as pltfrom matplotlib.dates import DayLocator, HourLocator, DateFormatter, drangeimport numpy as npdate1 = datetime.datetime(2000, 3, 2)date2 = datetime.datetime(2000, 3, 6)delta = datetime.timedelta(hours=6)dates = drange(date1, date2, delta)y = np.arange(len(dates))fig, ax = plt.subplots()ax.plot_date(dates, y ** 2)# this is superfluous, since the autoscaler should get it right, but# use date...
major_minor_demo
Major和Minor的演示演示如何使用Major和Minor代码。 两个相关的用户空类是Locators和Formatters。定位器确定刻度的位置,格式化程序控制刻度的格式。 默认情况下,小刻度线是关闭的(NullLocator和NullFormatter)。您可以通过设置次要定位器来转换w / o标签上的次要刻度。您还可以通过设置次要格式化程序为次要股票代码打开标签 制作一个主刻度线为20的倍数和小刻度为5的倍数的图。标记主要刻度与%d格式但不标记次刻度。 MultipleLocator自动收报机类用于在一些基数的倍数上放置滴答。 FormatStrFormatter使用字符串格式字符串(例如,’%d’或’%1.2f’或’%1.1f cm’)来格式化刻度线 pyplot interface grid命令一起更改y轴和y轴的主刻度线的网格设置。如果要控制给定轴的次刻度的网格,请使用例子中的方式。 1ax.xaxis.grid(True, which='minor') 请注意,您不应在不同的Axis之间使用相同的定位器,因为定位器存储对Axis数...
multiple_yaxis_with_spines
多个Yaxis与Spines使用共享x轴创建多个y轴。这是通过创建一个双轴,转动所有脊柱但右边的一个不可见并使用set_position偏移其位置来完成的。 请注意,此方法使用 matplotlib.axes.Axes 及其Spines。 寄生虫轴的另一种方法显示在Demo Parasite Axes 和 Demo Parasite Axes2示例中。 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import matplotlib.pyplot as pltdef make_patch_spines_invisible(ax): ax.set_frame_on(True) ax.patch.set_visible(False) for sp in ax.spines.values(): sp.set_visible(False)fig, host = plt.subplots()fig.su...
spine_placement_demo
Spine的放置演示调整轴Spine的位置和外观。 12import numpy as npimport matplotlib.pyplot as plt 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051fig = plt.figure()x = np.linspace(-np.pi, np.pi, 100)y = 2 * np.sin(x)ax = fig.add_subplot(2, 2, 1)ax.set_title('centered spines')ax.plot(x, y)ax.spines['left'].set_position('center')ax.spines['right'].set_color('none')ax.spines['bottom'].set_position('center&...
scalarformatter
使用ScalarFormat标记格式该示例显示了ScalarFormatter与不同设置的使用。 例子1:默认 例子2:没有图形偏移 例子3:使用Mathtext 123import matplotlib.pyplot as pltimport numpy as npfrom matplotlib.ticker import ScalarFormatter 例子1: 1234567891011121314151617181920212223x = np.arange(0, 1, .01)fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6))fig.text(0.5, 0.975, 'The new formatter, default settings', horizontalalignment='center', verticalalignment='top')ax1.plot(x * 1e5 + 1e10,...
spines
Spines图这个演示比较: 正常轴,四边都有spine; 仅在左侧和底部有spine的轴; 使用自定义边界限制spine范围的轴。 123456789101112131415161718192021222324252627282930313233343536import numpy as npimport matplotlib.pyplot as pltx = np.linspace(0, 2 * np.pi, 100)y = 2 * np.sin(x)fig, (ax0, ax1, ax2) = plt.subplots(nrows=3)ax0.plot(x, y)ax0.set_title('normal spines')ax1.plot(x, y)ax1.set_title('bottom-left spines')# Hide the right and top spinesax1.spines['right'].set_visible(False)ax1.spines['top']....
spines_bounds
自定义spine边界使用自定义边界来限制脊椎范围的spine演示。 12345678910111213141516171819202122232425262728293031import numpy as npimport matplotlib.pyplot as plt# Fixing random state for reproducibilitynp.random.seed(19680801)x = np.linspace(0, 2*np.pi, 50)y = np.sin(x)y2 = y + 0.1 * np.random.normal(size=x.shape)fig, ax = plt.subplots()ax.plot(x, y, 'k--')ax.plot(x, y2, 'ro')# set ticks and tick labelsax.set_xlim((0, 2*np.pi))ax.set_xticks([0, np.pi, 2*np.pi])ax.set_xticklabels(['0', r...
spines_dropped
掉落的spines从轴上偏移的spines的演示(a.k.a。“掉落的spines”)。 1234567891011121314151617181920212223import numpy as npimport matplotlib.pyplot as plt# Fixing random state for reproducibilitynp.random.seed(19680801)fig, ax = plt.subplots()image = np.random.uniform(size=(10, 10))ax.imshow(image, cmap=plt.cm.gray, interpolation='nearest')ax.set_title('dropped spines')# Move left and bottom spines outward by 10 pointsax.spines['left'].set_position(('outward', 10))ax.spines[...














