FaCoffee
FaCoffee

Reputation: 7929

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

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?

Upvotes: 10

Views: 31039

Answers (2)

lu5er
lu5er

Reputation: 3564

We can also use simply the color as a string like this,

line1 = ax1.plot(x, myvalues,'#333399', marker='o', label='My Blue values')

Upvotes: 4

tmdavison
tmdavison

Reputation: 69213

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')

Upvotes: 22

Related Questions