30

Black line in the following graph is plotting using the below command for matplotlib python

pylab.semilogy(xaxis, pq_averages, 'ks-',color='black', label='DCTCP-PQ47.5')

So 'ks-' part indicates solid line with square black marks. So it had solid squares for the plotted points. Can these squares be made hollow instead?

enter image description here

vaichidrewar
  • 9,251
  • 18
  • 72
  • 86

2 Answers2

50

Try adding markerfacecolor like so:

pylab.semilogy(xaxis, pq_averages, 'ks-', markerfacecolor='none', label='DCTCP-PQ47.5')
Ethan Coon
  • 751
  • 5
  • 16
Hugh Bothwell
  • 55,315
  • 8
  • 84
  • 99
  • 15
    Nice answer. Slightly improved would be to use `markerfacecolor='none'`, but in general, your solution will be perfect 90% of the time. – pelson Jun 15 '12 at 06:40
  • @pelson: yes, that is better - I was not aware that 'none' was accepted as a color. – Hugh Bothwell Jun 15 '12 at 12:42
  • 5
    @HughBothwell, can you edit the answer to use markerfacecolor='none'? – David Roundy Apr 30 '15 at 00:18
  • 2
    In matplotlib 3.0.2, there is apparently no markerfacecolor. facecolor='none' does work. – Alex I Feb 21 '19 at 07:13
  • For those who run out of space writing parameters for pyplot: `markerfacecolor` can be abbreviated `mfc`, there are also `mec` and even `mew`. See [documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib-pyplot-plot). – mins Apr 07 '23 at 21:07
  • For those that get `markerfacecolor` is an unexpected argument while trying a scatter plot, you should instead use `facecolors='none'`. [Reference](https://stackoverflow.com/a/59474817/5809639) – IndefiniteBen May 12 '23 at 14:58
11

Setting markerfacecolor='white' does not actually make them hollow, it makes them white. In order to make them hollow, you need to set markerfacecolor='none'. Additionally, you need to set markeredgecolor to the color you want. So:

pylab.semilogy(xaxis, pq_averages, 'ks-',color='black',
       label='DCTCP-PQ47.5', markerfacecolor='none', markeredgecolor='black')

Will do the job for you.

divenex
  • 15,176
  • 9
  • 55
  • 55
Saber
  • 194
  • 2
  • 8
  • 2
    "Additionally, you need to set `markerfacecolor` to the color you want." You mean `markeredgecolor` here, right? – lanery Nov 17 '16 at 20:48