Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change marker border width and hatch width?

In this example of a marker from my scatter plot I have set the color to green, and edge color to black, and hatch to "|". For the hatch pattern to show up at all I must set the edgecolor, however when I do, I get a very thick border around the marker. Two questions:

1) How can I to set the size of this border (preferably to 0)?

2) How can I increase the thickness of the hatch lines?

like image 216
David E Avatar asked Jan 14 '13 20:01

David E


People also ask

How do you change the color of a marker in Python?

All of the line properties can be controlled by keyword arguments. For example, you can set the color, marker, linestyle, and markercolor with: plot(x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12).

How do you change the color of a marker in Plotly?

How do you set a marker color for Plotly? To maximise visibility of each point, set the color as an rgba string that includes an alpha value of 0.5. This example sets the marker color to 'rgba(135, 206, 250, 0.5)' .

What is marker in Python?

Matplotlib marker module is a wonderful multi-platform data visualization library in python used to plot 2D arrays and vectors. Matplotlib is designed to work with the broader SciPy stack. The matplotlib markers module in python provides all the functions to handle markers.


2 Answers

  1. You just need to set the linewidth to control the marker border thickness.
  2. You can increase the density of hatching, by repeating symbols (in the example below, the '|' is repeated in the R/H pane; note that to obtain NW->SE diagonal lines the symbol must be escaped so needs twice as many characters to really double it -- '\\\\' is density 2 while '||||' is density 4). However, I don't think the thickness of individual lines within hatching is controllable.

See the code example below to produce scatter plots such as these: example hatching control

import matplotlib.pyplot as plt
# generate some data
x = [1,2,3,4,5,8]
y= [i**2 for i in x]
y2= [60-i**2+3*i for i in x]

# plot markers with thick borders
plt.subplot(121)
plt.scatter(x,y, s=500, marker='s', edgecolor='black', linewidth=3, facecolor='green', hatch='|')
# compare with no borders, and denser hatch.
plt.subplot(122)
plt.scatter(x,y2, s=500, marker='s', edgecolor='black', linewidth=0, facecolor='green', hatch='||||')

plt.show()

matplotlib documentation on collections and scatter.

like image 62
Bonlenfum Avatar answered Oct 22 '22 01:10

Bonlenfum


This is several years after you asked the question, but the only way I've found to do it is to change the matplotlib.rc.

You can do this either in the actual .rc file or within your python script, e.g.

import matplotlib as mpl

mpl.rc('hatch', color='k', linewidth=1.5)

This will make all of the hatch lines in your script black and thickness 1.5 rather than the default 1.0.

like image 8
Jacob Avatar answered Oct 22 '22 02:10

Jacob