Matplotlib图表样式参数(3)

    xiaoxiao2021-04-15  370

    #图表样式参数 #linestyle, style, color, market import numpy as np import pandas as pd import matplotlib.pyplot as plt % matplotlib inline #linestyle参数 plt.plot([i**2 for i in range(100)], linestyle = '-.') #'-' #'-.' #'--' #':' [<matplotlib.lines.Line2D at 0x1dedd1d1518>]

    df = pd.DataFrame(np.random.randn(1000)) #df.hist() #直方图 #密度图 df.plot(kind = 'kde', linestyle = ':') <matplotlib.axes._subplots.AxesSubplot at 0x1dedd227978>

    #marker参数,表示点的参数 s = pd.Series(np.random.randn(100).cumsum()) s.plot(linestyle = '--', linewidth = 0.5,alpha = 0.5, marker = '>') ''' . , o v < > 1 2 3 4 s p * h H + x D d | - ''' '\n.\n,\no\nv\n<\n>\n1\n2\n3\n4\ns\np\n*\nh\nH\n+\nx\nD\nd\n|\n-\n'

    x = np.random.randn(1000) y = np.random.randn(1000) plt.scatter(x, y, marker = '.', s = 10, alpha = 0.2) #alpha: 点的透明度 plt.xkcd() #color参数 plt.hist(np.random.randn(1000), color = 'r', alpha = 0.7) df = pd.DataFrame(np.random.randn(1000, 4), columns = list('ABCD')) df = df.cumsum() df.plot(style = '--.', alpha = 0.8, colormap = 'GnBu') #GnBu颜色集 #设置好看的颜色带 <matplotlib.axes._subplots.AxesSubplot at 0x1dedf5543c8>

    #style参数可以包含linestyle,marker, color ts = pd.Series(np.random.randn(1000).cumsum(), index = pd.date_range('1/1/2019', periods = 1000)) ts.plot(grid = True, figsize = (10, 2), style = '--.g') #style -> 风格字符串, 包括了linestyle(-),marker(.),color(g) <matplotlib.axes._subplots.AxesSubplot at 0x1dedf4b6908>

    ###***手绘风格 plt.xkcd() #整体风格样式 import matplotlib.style as psl print(plt.style.available) psl.use('seaborn-deep') ts = pd.Series(np.random.randn(1000).cumsum(), index = pd.date_range('1/1/2019',periods = 1000)) ts.plot(style = '--g.', grid = True, figsize = (10, 6)) ['bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn-bright', 'seaborn-colorblind', 'seaborn-dark-palette', 'seaborn-dark', 'seaborn-darkgrid', 'seaborn-deep', 'seaborn-muted', 'seaborn-notebook', 'seaborn-paper', 'seaborn-pastel', 'seaborn-poster', 'seaborn-talk', 'seaborn-ticks', 'seaborn-white', 'seaborn-whitegrid', 'seaborn', 'Solarize_Light2', 'tableau-colorblind10', '_classic_test'] <matplotlib.axes._subplots.AxesSubplot at 0x1dedfd70cc0>


    最新回复(0)