![]() ![]() Plt.plot(x, x**3, label='cubic',linewidth=3) Plt.plot(x, x**2, label='quadratic',linewidth=3) Plt.plot(x, x, label='linear',linewidth=3) We can change the dimensions of the graph using the figsize argument in plt.figure(). Plt.grid(color='red', alpha=0.2, linewidth=2) Plt.plot(months,salesC,linewidth=2,marker='o') Plt.plot(months,salesA,linewidth=2,marker='o') Linestyle: To change the line style of the grid lines. Linewidth: To alter the thickness of the grid lines. A few common attributes we can use are:Ĭolor: To change the color of the grid lines.Īlpha: To change the visibility of the grid lines. This is the default grid that gets added if we don’t use any customization. Let’s add one to the Monthly Sales Comparison Plot: plt.plot(months,salesA,linewidth=2) ![]() The plt.grid() function is used to add a grid to the plots. The values can be ‘upper left’, ‘upper right’, ‘lower left’, and ‘lower right’ of the corresponding graph. Loc is used to specify the location of the legend index. ![]() When plotting multiple lines in a graph, legends are used to describe the different elements using (). Here’s our sample data to show the monthly sales of a company: In Matplotlib, we do this using xlabel() and ylabel(). Most times, it’s necessary to add texts or labels to the axes of the graphs to help viewers understand what the plot is actually about. Markerfacecolor is used to change the color of the marker to highlight it more, and markeredgecolor is used to change the borders: plt.plot(x, marker='o', markersize=10, markeredgecolor='black', We can change the size of the markers using the argument markersize. Here’s how they can be viewed, along with a few examples: Like linestyle, there’s a long list of selections of linemarkers. Markers are used to highlight points on the graph. Linewidth is used to change the thickness of the plot: plt.plot(x,linestyle='dashdot',color='green',linewidth=5) Let’s try out a few linestyles and some other arguments: plt.plot(x,linestyle=':',color='red') Here’s a list of all the available options: import matplotlib Matplotlib offers a variety of linestyles that can be customized using the ls or linestyle argument in the plot(). Let’s plot a simple line graph using sample data. Customizing plots using Matplotlib Line styles png images of the plot directly into the IPython Notebook. The %matplotlib inline command is used to embed static. Or, by running this command in cmd: conda install -c conda-forge matplotlib Matplotlib can installed directly from Jupyter Notebook by running the command: !pip install matplotlib Image source: Matplotlib Data visualization using Matplotlib Installation and loading ![]() It offers a variety of plots like Line, Scatter, Bar, Histogram, Box, etc. It is the go-to Python library for graphs and visualizations. Matplotlib was created by John Hunter during his post-doctoral research in neurobiology and released in 2003. subplots ( 2, 2, sharex = True, sharey = True ) # Creates figure number 10 with a single subplot # and clears it if it already exists. subplots ( 2, 2, sharex = 'all', sharey = 'all' ) # Note that this is the same as plt. subplots ( 2, 2, sharey = 'row' ) # Share both X and Y axes with all subplots plt. subplots ( 2, 2, sharex = 'col' ) # Share a Y axis with each row of subplots plt. scatter ( x, y ) # Share a X axis with each column of subplots plt. subplots ( 2, 2, subplot_kw = dict ( polar = True )) axes. scatter ( x, y ) # Creates four polar axes, and accesses them through the returned array fig, axes = plt. set_title ( 'Simple plot' ) # Creates two subplots and unpacks the output array immediately f, ( ax1, ax2 ) = plt. sin ( x ** 2 ) # Creates just a figure and only one subplot fig, ax = plt. Theĭimensions of the resulting array can be controlled with the squeeze **fig_kwĪll additional keyword arguments are passed to theįig : Figure ax : axes.Axes object or array of Axes objects.Īx can be either a single Axes object or anĪrray of Axes objects if more than one subplot was created. subplot_kw : dict, optionalĭict with keywords passed to the GridSpecĬonstructor used to create the grid the subplots are placed on. Num : integer or string, optional, default: NoneĪ pyplot.figure keyword that sets the figure number or label. If False, no squeezing at all is done: the returned Axes object isĪlways a 2D array containing Axes instances, even if it ends up
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |