Using multiple linestyles

One user asked if it’s possible to plot two lines from python, with different linestyles.

import numpy as np
x=np.arange(11)
y1=np.arange(10)
y2=np.arange(10)+1
w1=CreateWorkspace(x,y1,np.sqrt(y1))
w2=CreateWorkspace(x,y2,np.sqrt(y2))
l=plot(w1,Layer.Line,linestyle=’-’)
l=plot(w2,Layer.Line,linestyle=’–’,hold=‘on’)

If I execute line by line, the first line is continuous, but, when I execute the last line, both lines become dashed.

Thanks.

Andrei

In my case, it doesn’t even plot with lines. If it helps, I’ve set my default plot 2D style to be scatter and axis to be log scale. Can this default setting interfere linestyles?

Thanks,

Unfortunately pymantidplot.pyplot doesn’t support controlling the line styles individually. That is one of the many features of mantidplot that are not directly supported.
It can be done, but it is undocumented, and there is no “matplotlib-like” interface for it. Modifying Andrei’s example, if you want to plot a first line as solid line and then a second line as a dashed-dotted line you can do as follows:

import numpy as np
x=np.arange(11)
y1=np.arange(10)
y2=np.arange(10)+1
w1=CreateWorkspace(x,y1,np.sqrt(y1))
w2=CreateWorkspace(x,y2,np.sqrt(y2))
lines1=plot(w1, 0, linestyle='-')
lines2=plot(w2, 0, hold='on')

line = lines2[0]
line._graph.activeLayer().setCurveLineStyle(0, pymantidplot.pyplot.__linestyle_to_qt_penstyle['-.'])
# The '0' passed to setCurveLineStyle() is the index of the line
# Style alternatives: '-', '--', '-.', ':'

@dokira: if you post an example we could take a look at that issue. The default curve style in the Mantid settings should not interfere with the linestyle keyword argument, in principle.

Unfortunately, this example doesn’t work in my mantidplot. I copied and pasted the code and ran in the script interpreter of mantidplot. But still get Marker (default) plots not linestyles.

Best regards,