For this article, we will use the Titanic Dataset. We will use a dataset to simulate data visualization of a real-life project. Now that we’ve learned the basics of customization using line graphs, we will now cover the other different types of plots and graphs that assist with data visualization. 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,salesB,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. The center of the marker is located at (0,0) and the size is normalized, such that the created path is encapsulated inside the unit cell.įrom the table above, we can see that in matplotlib, markers take different symbols: ‘H’ for hexagon marker, ‘s’ for star marker, ‘d’ for thin diamond marker, etc.Matplotlib was created by John Hunter during his post-doctoral research in neurobiology and released in 2003. This marker can also be a tuple (numsides, style, angle), which will create a custom, regular symbol.Ī list of (x, y) pairs used for Path vertices. Marker references in Pythonīelow is a table showing the list of some markers present in the matplot library and their respective descriptions. You can use the keyword argument marker to emphasize which marker you want on the line of plot. Markers are used in matplot library ( matplotlib) to simply enhance the visual of line size of a plot.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |