![]() ![]() Colour specifiersĬolours are defined by a string value, but there are various ways to do this. Since the default resolution for a graph image created by Matplotlib is 100 pixels per inch this means that the linewidth parameter of a plot is approximately equal to the line width in pixels. The line width is measured in points, where one point is one seventy-second of an inch (ie there are 72 points in an inch). You can also use the lw parameter - it does exactly the same thing, but it is a shorter name. The line width of a Matplotlib plot is controlled by the linewidth parameter. dash_capstyle="round" - this causes each dash to have rounded ends (rather than the default square ends).linestyle=(0, (4, 2, 1, 2)) sets the dash pattern, see below.linewidth=6 sets the line thickness to 6 pixels.color="#ff8000" sets the colour to hex value ff8000 (orange), see below.linewidth=4 sets the line thickness to 4 pixels.įor the second plot, we supply these parameters:.color="cadetblue" sets the colour to a CSS named colour (in this case a blue-green colour).The data is created in the same way as before, so we haven't duplicated the code.įor the first plot, we supply these parameters: plot ( x, y1, color = "cadetblue", linewidth = 4 ) plt. Named parameters give us more options for each aspect of the appearance: There is no marker.Īs an alternative, we can set the colour and line style for a graph using named parameters of the plot function. "-.r" represents the line style dash-dot ("-.") and the colour red ("r").The part specifies the colour of the line and/or markers: _ (underline character) horizontal line.number 1 tri down (tri is a 3 pointed "star" shape).(greater than character) gives a triangle pointing right.^ (hat character) gives a triangle pointing up.letter v gives a triangle, pointing down.letter o gives a circle, larger that the point marker., (comma character) gives a single pixel marker. ![]() (full stop character) gives a small circle or "point" marker The part specifies the shape of the markers (see later). We can set the colour and line style for a graph by adding an extra string parameter to the plot function: This is useful for quick plots, but there may be situations where we want more control over the styles. ![]() When we plot two data sets, the second one is automatically coloured orange to distinguish it. This uses thin blue lines for the graph lines and small blue dots for the markers. Default stylingĪll the examples in this course so far have used default styling. The code examples in this article are here on github, in the files linestyles.py and markerstyles.py. ![]() We will look at both methods here, but first we will look at the default styling. Or we can use formatting parameters, which have a lot more flexibility. We can use format strings, which are very simple to add but have a limited number of options. Markers are the dots on a scatter plot or stem plot, but they can also be added to a line plot. Changing the colour, shape, and other attributes of the markers in a plot.Changing the colour, thickness, and dash style of the lines in a plot.This applies to line plots, scatter plots, and stem plots. In this article, we will learn how to apply styling to plots. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |