100 likes | 113 Views
Setting lines ,changing colors and adding markers are some of the features of matplotlib .Different styles of lines can also be used to plot .Special plots can also be drawn using Matplotlib.Here is the highlight on these topics.<br>To learn more visit: http://bit.ly/DatascienceCourse
E N D
MATPLOTLIB PART II
The following format string characters are accepted to control the line style or marker: character description'-‘ solid line style'--‘ dashed line style'-.‘ dash-dot line style':‘ dotted line style'.‘ point marker',‘ pixel marker'o‘ circle marker'v‘ triangle_down marker'^‘ triangle_up marker'<‘ triangle_left marker'>‘ triangle_right marker'1‘ tri_down marker'2‘ tri_up marker'3‘ tri_left marker'4‘ tri_right marker's‘ square marker'p‘ pentagon marker'*‘ star marker'h‘ hexagon1 marker'H‘ hexagon2 marker'+‘ plus marker'x‘ x marker'D‘ diamond marker'd‘ thin_diamond marker'|‘ vline marker‘_‘ hline marker
There are several parameters that determine what the figure looks like:
Example • fig = plt.figure() axes1 = fig.add_axes([0.1, 0.1, 0.9,0.9]) axes1.plot(arr1, arr2, 'b--') axes1.plot(arr2, arr1, 'r.-') • O/P:
Alpha parameter can be mentioned that defines the transparency in the plot. • Eg: fig = plt.figure() axes1 = fig.add_axes([0.1, 0.1, 0.9,0.9]) axes1.plot(arr1, arr2, color = '#808000', lw = 10) axes1.plot(arr2, arr1, color = '#00FF00', lw = 0.25) axes1.plot(arr1, arr1*2, color = '#00FF00', lw = 1)
Setting line,changing line colors and adding markers The following color abbreviations are supported: Character color ‘b’ blue ‘g’ green ‘r’ red ‘c’ cyan ‘m’ magenta ‘y’ yellow ‘k’ black ‘w’ white For other color shades hexadecimal color coding can be used.
Ls parameter defines the line style as mentioned in the previous table . • Lw defines the line width that we wish to have in the plot • Eg:fig = plt.figure() axes1 = fig.add_axes([0.1, 0.1, 0.9,0.9]) #l,b,w,h -[0 and 1] axes1.plot(arr1, arr2, color = '#808000', lw = 10, ls = '--')axes1.plot(arr2, arr1, color = '#00FF00', lw = 3.25, ls = ':')axes1.plot(arr1, arr1*2, color = '#00FF00', lw = 1, ls = '-.')
Eg 2:fig = plt.figure()axes1 = fig.add_axes([0.1, 0.1, 0.9,0.9]) #l,b,w,h -[0 and 1]axes1.plot(arr1, arr1*2, color = '#00FF00', lw = 1, ls = '.', marker= 's', markersize = 10, markerfacecolor = 'red') • O/P: