How To Register Matplotlib Converters
1d plotting¶
ProPlot adds new features to various Axes plotting methods thanks to a ready of wrapper functions. These features are a strict superset of the existing matplotlib API – if you desire, y'all tin can utilise plotting commands exactly as you e'er have.
Standardized input¶
The standardize_1d wrapper is used to standardize the positional arguments for several different plotting functions. standardize_1d allows y'all to optionally omit 10 coordinates (in which case they are inferred from the y coordinates) or pass 2d y coordinate arrays (in which instance the plotting method is called with each column of the array).
Pandas and xarray¶
The standardize_1d wrapper also supports integration with pandas DataFrame s and xarray DataArray s. When you pass a DataFrame or DataArray to any plotting command, the x-axis label, y-axis label, fable label, colorbar label, and/or title are configured from the metadata. This restores some of the convenience you go with the builtin pandas and xarray plotting functions. This feature is optional; installation of pandas and xarray are not required.
import xarray as xr import numpy equally np import pandas as pd # DataArray state = np . random . RandomState ( 51423 ) data = np . sin ( np . linspace ( 0 , 2 * np . pi , 20 ))[:, None ] \ + land . rand ( 20 , 8 ) . cumsum ( axis = ane ) da = xr . DataArray ( data , dims = ( '10' , 'cat' ), coords = { 'ten' : xr . DataArray ( np . linspace ( 0 , ane , 20 ), dims = ( 'x' ,), attrs = { 'long_name' : 'distance' , 'units' : 'km' }), 'cat' : xr . DataArray ( np . arange ( 0 , eighty , x ), dims = ( 'cat' ,), attrs = { 'long_name' : 'parameter' , 'units' : 'K' }) }, name = 'position serial' ) # DataFrame ts = pd . date_range ( 'ane/1/2000' , periods = 20 ) data = ( np . cos ( np . linspace ( 0 , 2 * np . pi , 20 )) ** 4 )[:, None ] + state . rand ( xx , 5 ) ** two df = pd . DataFrame ( information , index = ts , columns = [ 'foo' , 'bar' , 'baz' , 'zap' , 'baf' ]) df . name = 'time series' df . index . name = 'fourth dimension (s)' df . columns . name = 'columns'
import proplot as plot f , axs = plot . subplots ( ncols = 2 , axwidth = 2.2 , share = 0 ) axs . format ( suptitle = 'Automated subplot formatting' ) # Plot DataArray cycle = plot . Bike ( plot . shade ( 'lite blueish' , 0.4 ), fade = xc , infinite = 'hpl' ) axs [ 0 ] . plot ( da , bike = cycle , lw = 3 , colorbar = 'ul' , colorbar_kw = { 'locator' : 20 }) # Plot Dataframe bike = plot . Cycle ( plot . shade ( 'jade' , 0.four ), fade = 90 , infinite = 'hpl' ) axs [ 1 ] . plot ( df , cycle = wheel , lw = iii , legend = 'uc' )
/home/docs/checkouts/readthedocs.org/user_builds/proplot/conda/v0.three.ane/lib/python3.7/site-packages/pandas/plotting/_matplotlib/converter.py:103: FutureWarning: Using an implicitly registered datetime converter for a matplotlib plotting method. The converter was registered by pandas on import. Hereafter versions of pandas will require you to explicitly annals matplotlib converters. To register the converters: >>> from pandas.plotting import register_matplotlib_converters >>> register_matplotlib_converters() warnings.warn(msg, FutureWarning)
(<matplotlib.lines.Line2D at 0x7f8a29927a90>, <matplotlib.lines.Line2D at 0x7f8a298a7748>, <matplotlib.lines.Line2D at 0x7f8a298a7be0>, <matplotlib.lines.Line2D at 0x7f8a298a7780>, <matplotlib.lines.Line2D at 0x7f8a2986e4a8>)
On-the-fly fault bars¶
Thanks to the add_errorbars wrapper, you can add fault confined on-the-fly by passing certain keyword args to plot , scatter , bar , barh , or violinplot . If yous pass 2d arrays to these commands with means=True or medians=Truthful , the means or medians of each column are drawn equally points, lines, or bars, and error confined are fatigued to represent the spread in each cavalcade. You tin draw both thin "bars" with optional whiskers, and thick "boxes" overlayed on superlative of these bars. You can also pass error bar coordinates manually with the bardata and boxdata keyword args. See add_errorbars for details.
import proplot as plot import numpy every bit np import pandas as pd plot . rc [ 'title.loc' ] = 'uc' plot . rc [ 'axes.ymargin' ] = plot . rc [ 'axes.xmargin' ] = 0.05 state = np . random . RandomState ( 51423 ) data = state . rand ( 20 , 8 ) . cumsum ( axis = 0 ) . cumsum ( axis = 1 )[:, :: - 1 ] \ + 20 * state . normal ( size = ( twenty , 8 )) + 30 f , axs = plot . subplots ( nrows = 3 , attribute = 1.5 , axwidth = 3 , share = 0 , hratios = ( 2 , 1 , one )) axs . format ( suptitle = 'Error bars with various plotting commands' ) # Request add_errorbars to summate confined ax = axs [ 0 ] obj = ax . barh ( information , colour = 'crimson orangish' , means = Truthful ) ax . format ( championship = 'Column statistics' ) # Showing a standard deviation range instead of percentile range ax = axs [ one ] ax . besprinkle ( information , color = 'k' , mark = '10' , markersize = 50 , barcolor = 'gray5' , medians = True , barstd = Truthful , barrange = ( - 1 , 1 ), barzorder = 0 , boxes = False , capsize = 2 ) # Supplying error bar data manually ax = axs [ two ] boxdata = np . percentile ( data , ( 25 , 75 ), axis = 0 ) bardata = np . percentile ( information , ( 5 , 95 ), centrality = 0 ) ax . plot ( information . hateful ( axis = 0 ), boxes = False , marker = 'o' , markersize = five , edgecolor = 'm' , colour = 'cerulean' , boxdata = boxdata , bardata = bardata ) # Formatting axs [ 0 ] . format ( ylabel = 'column number' , title = 'Bar plot' , ygrid = False ) axs [ ane ] . format ( title = 'Scatter plot' ) axs [ 2 ] . format ( championship = 'Line plot' ) axs [ 1 :] . format ( xlabel = 'column number' , xticks = 1 , xgrid = Fake ) plot . rc . reset ()
Bar plots¶
bar_wrapper and cycle_changer make it easier to generate useful bar plots. You can now pass second arrays to bar or barh , and columns of information will be grouped or stacked together. As well, bar and barh now use default x and y coordinates if y'all failed to provide them explicitly, but like plot . See bar_wrapper for details.
import proplot as plot import numpy as np import pandas every bit pd plot . rc . titleloc = 'uc' plot . rc . margin = 0.05 f , axs = plot . subplots ( nrows = ii , attribute = 2 , axwidth = iii.v , share = 0 , hratios = ( iii , 2 )) country = np . random . RandomState ( 51423 ) data = state . rand ( 5 , 5 ) . cumsum ( axis = 0 ) . cumsum ( axis = 1 )[:, :: - 1 ] data = pd . DataFrame ( data , columns = pd . Index ( np . arange ( i , vi ), proper name = 'cavalcade' ), index = pd . Index ([ 'a' , 'b' , 'c' , 'd' , 'e' ], proper name = 'row idx' )) ax = axs [ 0 ] obj = ax . bar ( data , cycle = 'Reds' , colorbar = 'ul' , edgecolor = 'red9' , colorbar_kw = { 'frameon' : Fake }) ax . format ( xlocator = 1 , xminorlocator = 0.five , ytickminor = False , title = 'Side-by-side' , suptitle = 'Bar plot wrapper demo' ) ax = axs [ 1 ] obj = ax . barh ( data . iloc [:: - 1 , :], cycle = 'Blues' , legend = 'ur' , edgecolor = 'blue9' , stacked = True ) ax . format ( title = 'Stacked' ) axs . format ( grid = Faux ) plot . rc . reset ()
Expanse plots¶
To make expanse plots, use the convenient fill_between aliases surface area and areax . These are wrapped with fill_between_wrapper and fill_betweenx_wrapper .
The fill_between wrappers enable "stacking" successive columns of a 2D input assortment like in pandas . They also add a new negpos keyword for creating expanse plots that modify color when the fill boundaries cross each other. The most common utilize instance for this is highlighting the negative and positive areas underneath a line, as shown beneath.
import proplot every bit plot import numpy as np plot . rc . margin = 0 f , axs = plot . subplots ( assortment = [[ i , 2 ], [ three , 3 ]], hratios = ( one , 0.8 ), share = 0 ) axs . format ( xlabel = 'xlabel' , ylabel = 'ylabel' , suptitle = 'Area plot demo' ) state = np . random . RandomState ( 51423 ) information = land . rand ( 5 , 3 ) . cumsum ( axis = 0 ) cycle = ( 'gray3' , 'gray5' , 'gray7' ) # second arrays ax = axs [ 0 ] ax . areax ( np . arange ( 5 ), data , data + state . rand ( 5 )[:, None ], bike = bike , alpha = 0.v , fable = 'uc' , legend_kw = { 'middle' : True , 'ncols' : ii , 'labels' : [ 'z' , 'y' , 'qqqq' ]}, ) ax . format ( title = 'Fill between columns' ) ax = axs [ ane ] ax . area ( np . arange ( 5 ), data , stacked = True , cycle = bicycle , alpha = 0.8 , legend = 'ul' , legend_kw = { 'center' : Truthful , 'ncols' : two , 'labels' : [ 'z' , 'y' , 'qqqq' ]}, ) ax . format ( title = 'Stack between columns' ) # Positive and negative colors ax = axs [ 2 ] data = 5 * ( state . rand ( twenty ) - 0.5 ) ax . surface area ( information , negpos = True , negcolor = 'blue7' , poscolor = 'red7' ) ax . format ( title = 'Negative and positive data' , xlabel = 'xlabel' , ylabel = 'ylabel' ) axs . format ( grid = False ) plot . rc . reset ()
Box plots and violin plots¶
boxplot and violinplot are now wrapped with boxplot_wrapper , violinplot_wrapper , and cycle_changer , making it much easier to plot distributions of data with aesthetically pleasing default settings and automatic axis labeling.
import proplot every bit plot import numpy equally np import pandas as pd N = 500 country = np . random . RandomState ( 51423 ) f , axs = plot . subplots ( ncols = 2 ) information = state . normal ( size = ( N , 5 )) + two * ( state . rand ( N , 5 ) - 0.v ) * np . arange ( v ) data = pd . DataFrame ( data , columns = pd . Index ( [ 'a' , 'b' , 'c' , 'd' , 'due east' ], name = 'xlabel' )) ax = axs [ 0 ] # , boxprops={'color':'C0'})#, labels=data.columns) obj1 = ax . boxplot ( data , lw = 0.7 , marker = 'x' , fillcolor = 'gray5' , medianlw = 1 , mediancolor = 'k' ) ax . format ( title = 'Box plots' , titleloc = 'uc' ) ax = axs [ one ] obj2 = ax . violinplot ( data , lw = 0.seven , fillcolor = 'gray7' , points = 500 , bw_method = 0.3 , means = True ) ax . format ( title = 'Violin plots' , titleloc = 'uc' ) axs . format ( ymargin = 0.1 , xmargin = 0.one , grid = Faux , suptitle = 'Boxes and violins demo' )
/home/docs/checkouts/readthedocs.org/user_builds/proplot/conda/v0.3.1/lib/python3.7/site-packages/proplot/utils.py:102: ProPlotWarning: Got conflicting or indistinguishable keyword args, using the first i: {'lw': 0.seven, 'linewidth': 0.vii}
Parametric plots¶
Y'all can draw "parametric" plots in ProPlot using the parametric method or by passing the cmap keyword argument to plot . "Parametric" plots are line collections that map individual line segments to private colors, where each color represents a parametric coordinate (e.chiliad. time). Parametric coordinates must exist passed with the values keyword argument. See parametric for details.
import proplot every bit plot import numpy as np North = l cmap = 'IceFire' values = np . linspace ( - N / 2 , N / 2 , N ) f , axs = plot . subplots ( share = 0 , ncols = 2 , wratios = ( two , 1 ), axwidth = '6cm' , aspect = ( ii , 1 )) axs . format ( suptitle = 'Parametric plots demo' ) # Smooth gradations ax = axs [ 0 ] land = np . random . RandomState ( 51423 ) m = ax . plot (( state . rand ( N ) - 0.5 ) . cumsum (), state . rand ( Northward ), cmap = cmap , values = values , lw = seven , extend = 'both' ) ax . format ( xlabel = 'xlabel' , ylabel = 'ylabel' , title = 'Line with smoothen gradations' ) ax . format ( xlim = ( - ane , 5 ), ylim = ( - 0.two , 1.2 )) ax . colorbar ( m , loc = 'b' , characterization = 'parametric coordinate' , locator = 5 ) # Step gradations N = 12 ax = axs [ 1 ] values = np . linspace ( - North / 2 , N / ii , N + one ) radii = np . linspace ( i , 0.2 , N + 1 ) angles = np . linspace ( 0 , 4 * np . pi , N + 1 ) x = radii * np . cos ( ane.four * angles ) y = radii * np . sin ( 1.four * angles ) grand = ax . plot ( x , y , values = values , linewidth = xv , interp = False , cmap = cmap ) ax . format ( xlim = ( - 1 , one ), ylim = ( - i , 1 ), title = 'Step gradations' , xlabel = 'cosine angle' , ylabel = 'sine bending' ) ax . colorbar ( m , loc = 'b' , maxn = 10 , characterization = f 'parametric coordinate' )
<matplotlib.colorbar.Colorbar at 0x7f8a285e9eb8>
Besprinkle plots¶
Thanks to scatter_wrapper and cycle_changer , scatter at present accepts 2D arrays, just like plot . Besides, successive calls to scatter at present use the belongings cycler properties (e.g. color , marker , and markersize ), and to reduce defoliation, scatter optionally accepts keywords that look similar plot keywords (e.g. colour instead of c and markersize instead of s ). You can as well pass colormaps to scatter simply as with matplotlib.
We are as well considering supporting 2d array input and property wheel iteration for more obscure matplotlib plotting commands similar stem , footstep , vlines , and hlines . Stay tuned!
import proplot every bit plot import numpy equally np import pandas as pd f , axs = plot . subplots ( ncols = 2 , share = i ) state = np . random . RandomState ( 51423 ) x = ( state . rand ( 20 ) - 0 ) . cumsum () data = ( country . rand ( 20 , 4 ) - 0.5 ) . cumsum ( centrality = 0 ) data = pd . DataFrame ( data , columns = pd . Index ([ 'a' , 'b' , 'c' , 'd' ], name = 'label' )) # Besprinkle demo ax = axs [ 0 ] ax . format ( title = 'Extra prop wheel backdrop' , suptitle = 'Scatter plot demo' ) obj = ax . scatter ( x , data , legend = 'ul' , cycle = 'warm' , legend_kw = { 'ncols' : 2 }, cycle_kw = { 'marker' : [ 'x' , 'o' , 'x' , 'o' ], 'markersize' : [ 5 , ten , 20 , 30 ]}) ax = axs [ 1 ] ax . format ( title = 'Scatter plot with cmap' ) data = land . rand ( ii , 100 ) obj = ax . besprinkle ( * data , color = data . sum ( axis = 0 ), size = state . rand ( 100 ), smin = three , smax = 30 , marker = 'o' , cmap = 'plum' , colorbar = 'lr' , vmin = 0 , vmax = 2 , colorbar_kw = { 'label' : 'label' , 'locator' : 0.5 }) axs . format ( xlabel = 'xlabel' , ylabel = 'ylabel' )
How To Register Matplotlib Converters,
Source: https://proplot.readthedocs.io/en/v0.3.1/1dplots.html
Posted by: roundsbrong1962.blogspot.com

0 Response to "How To Register Matplotlib Converters"
Post a Comment