Matplotlib Tutorial – How to Control Matplotlib Styles

In this Matplotlib Tutorial we are going to learn How to Control Matplotlib Styles, so you can customize Matplotlib styles in three sections, you can customize Colors, Line Styles and Marker Styles.

 

 

Also you can check More GUI Development Tutorials in the below link.

1: PyQt5 GUI Development Tutorials

2: TKinter GUI Development Tutorials

3: Pyside2 GUI Development Tutorials 

4: Kivy GUI Development Tutorials

 

 

 

 

Controlling Colors 

Sometimes when you are plotting, you want to customize the colors for Matplotlib graph, you want to Control Matplotlib Styles , for example if you are plotting lines, you can customize every color for lines.

 

So you can see in the above code we have specified the color for our lines.

 

 

 

 

 

If you run the code this will be the result.

Matplotlib Tutorial - How to Control Matplotlib Styles
Matplotlib Tutorial – How to Control Matplotlib Styles

 

 

 

 

 

 

There are different colors in Matplotlib, this is the table for Matplotlib colors.

Color Color Name
b blue
c cyan
g green
k black
m magenta
r red
w white
y yellow

 

 

 

 

 

Controlling Line Styles 

The lines that we have saw in the above example, it is just a line without any dots or dashes, in Matplotlib also you can use different line styles.

 

 

 

So you can see that in the plot function we have used our line styles.

 

 

 

 

 

If you run the complete code this will be the result.

Matplotlib Tutorial - How to Control Matplotlib Styles
Matplotlib Tutorial – How to Control Matplotlib Styles

 

 

 

 

 

There are different line styles in Matplotlib, this is the table for Matplotlib line styles.

Style Abbreviation  Style 
Solid Line
Dashed Line
-.  Dash Dot Line
: Dotted Line

 

 

 

 

 

Control Marker Styles 

Matplotlib provides a lot of customization options for markers.

 

 

 

 

 

 

If you run the code this will be the result.

Matplotlib Tutorial - How to Control Matplotlib Styles
Matplotlib Tutorial – How to Control Matplotlib Styles

 

 

 

 

 

There are different Marker Styles in Matplotlib that you can, we have just used some of them in this table.

 

Marker abbreviation Marker style
. Point marker
, Pixel marker
o Circle marker
v Triangle down
_ Horizontal line
| Vertical line
d Thin diamond
D Diamond marker
+ Plus marker

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×