![]() ![]() The following code shows how to create multiple lines with different thicknesses and create a legend that displays the the thickness of each line accordingly: import matplotlib. pyplot as pltĮxample 3: Adjust Line Thickness in Legends The following code shows how to adjust the thickness of multiple lines at once: import matplotlib. To draw a grid with grid lines at the ticks use plt.grid(). #create line plot with line width set to 3Įxample 2: Adjust the Thickness of Multiple Lines Labels can be rotated by adding parameter rotationangleindegrees. In addition, because of the way we plot the data, all the polygons are colored in the same (default) color. Import numpy as np #define x and y values Note how the lines are much thinner and discreet. The following code shows how to create a simple line chart and set the line width to 3: import matplotlib. ![]() Example 1: Adjust the Thickness of One Line This tutorial provides several examples of how to use this function in practice. (x, y, linewidth=1.5)īy default, the line width is 1.5 but you can adjust this to any value greater than 0. G4.You can easily adjust the thickness of lines in Matplotlib plots by using the linewidth argument function, which uses the following syntax: G2.set_title("Systolic vs Diastolic blood pressure") df.plot(ax = g4, color='gray') G3.set_title("Distribution of systolic blood pressure") df.plot('BPXSY1', 'BPXDI1', kind='scatter', ax = g2, alpha=0.3) G1.set_title("Bar plot of Systolic blood pressure for different marital status") df.hist(ax = g3, orientation = 'horizontal', color='gray') ![]() G4 = plt.subplot(grid) df.groupby('DMDMARTL').mean().plot(kind = 'bar', ax = g1) Grid = plt.GridSpec(4, 4, wspace =0.3, hspace = 0.8) g1 = plt.subplot(grid) Now as you know how to index the grid and make custom-shaped plots, let’s make another one and put some real plots in them. It is a standard convention to import Matplotlibs pyplot library as plt. ‘grid’ means row index 2 and column-index 2 to end. To build a line plot, first import Matplotlib. The column index starts at 2 and goes till the end. So the column index becomes 0:2 which can be written as :2. The column-index starts at 0 and takes 2 plots. The row index starts at 1 and goes till the end. Using ‘grid’ we are making that big square-shaped one. 0 means row-index is 0 and 3 means column-index is 3. But when it starts with 0, it can be written as :3. import numpy as np import matplotlib.pyplot as plt x 1,2,3,4 y 1,2,3,4 plt.plot(x,y) plt.show() Results in: You can feed any number of arguments into the plot () function. Because it is the first row, row-index is 0, and column index is 0 to 3 as we are taking the first three columns. This is because plot () can either draw a line or make a scatter plot. ‘grid’ here is taking the first three plots of the first row and making a bigger plot. Using this code we are indexing the grid and making a custom shape. Since the scatter plot marks patterns are omitted, we get line plots without the scatter plot corresponding to the sampled points. ![]() Next, we indexed through the grids to make custom sizes of plots. fig, ax = plt.subplots(2, 3, figsize = (15, 10))įig.tight_layout(pad = 2) ax.scatter(df, df)ĭf.groupby('DMDEDUC2').mean().plot(ax = ax, kind='pie', colors = ) and think about the parameters that control the look of lines vs. NumPy-Matplotlib Scatter Plot for 2 categories of 25 points each, randomly generated import. The scatter plot is a mainstay of statistical visualization. So, here is how to access the ‘ax’ elements and set plots in them. The simplest example to plot a line is as follows. We will access each ‘ax’ element by indexing simply like a two-dimensional array. I will make a 2×3 array of plots again and set plots in the ‘ax’ elements. Here I am importing a dataset using pandas: df = pd.read_csv('nhanes_2015_2016.csv') #THIN LINE SCATTER PLOT MATPLOTLIB DOWNLOAD#Please feel free to download the dataset and follow along. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |