Matplotlib: how to plot with a specific hex color and a specific marker?

FaCoffee picture FaCoffee · Nov 13, 2015 · Viewed 11.6k times · Source

I need to produce a plot in which a line is plotted in Pigment Blue (hex= #333399) and with the o marker.

I know I can plot the line in Blue with the o marker by just calling:

line1 = ax1.plot(x, myvalues,'bo-', label='My Blue values')

Question: how should the line be changed if I wanted to still keep the marker and change the color from b to #333399?

Answer

tmdavison picture tmdavison · Nov 13, 2015

You can change lots of things if you use the kwargs to plot (which get passed to Line2D) instead of the shorthand 'bo-'. For example:

line1 = ax1.plot(
          x, myvalues,
          marker = 'o',
          linestyle = '-',
          markerfacecolor='#333399',
          markeredgecolor='k',
          label='My Blue values')