<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 The Lines Mark
Lines is a Mark object that is primarily used to visualize quantitative data. It works particularly well for continuous data, or when the shape of the data needs to be extracted.
Introduction
The Lines object provides the following features
Step1:  Random Data Generation
Step2:  Basic Line Chart
Using the bqplot, object oriented API, we can generate a Line Chart with the following code snippet
Step3:  The x attribute refers to the data represented horizontally, while the y attribute refers the data represented vertically.
We can explore the different attributes by changing each of them for the plot above
Step4:  In a similar way, we can also change any attribute after the plot has been displayed to change the plot. Run each of the cells below, and try changing the attributes to explore the different features and how they affect the plot.
Step5:  To switch to an area chart, set the fill attribute, and control the look with fill_opacities and fill_colors.
Step6:  While a Lines plot allows the user to extract the general shape of the data being plotted, there may be a need to visualize discrete data points along with this shape. This is where the markers attribute comes in.
Step7:  The marker attributes accepts the values square, circle, cross, diamond, square, triangle-down, triangle-up, arrow, rectangle, ellipse. Try changing the string above and re-running the cell to see how each marker type looks.
Plotting a Time-Series
The DateScale allows us to plot time series as a Lines plot conveniently with most date formats.
Step8:  Plotting Multiples Sets of Data with Lines
The Lines mark allows the user to plot multiple y-values for a single x-value. This can be done by passing an ndarray or a list of the different y-values as the y-attribute of the Lines as shown below.
Step9:  We pass each data set as an element of a list. The colors attribute allows us to pass a specific color for each line.
Step10:  Similarly, we can also pass multiple x-values for multiple sets of y-values
Step11:  Coloring Lines according to data
The color attribute of a Lines mark can also be used to encode one more dimension of data. Suppose we have a portfolio of securities and we would like to color them based on whether we have bought or sold them. We can use the color attribute to encode this information.
Step12:  We can also reset the colors of the Line to their defaults by setting the color attribute to None.
Step13:  Patches
The fill attribute of the Lines mark allows us to fill a path in different ways, while the fill_colors attribute lets us control the color of the fill
<ASSISTANT_TASK:>
Python Code:
import numpy as np  # For numerical programming and multi-dimensional arrays
from pandas import date_range  # For date-rate generation
from bqplot import LinearScale, Lines, Axis, Figure, DateScale, ColorScale
Explanation: The Lines Mark
Lines is a Mark object that is primarily used to visualize quantitative data. It works particularly well for continuous data, or when the shape of the data needs to be extracted.
Introduction
The Lines object provides the following features:
Ability to plot a single set or multiple sets of y-values as a function of a set or multiple sets of x-values
Ability to style the line object in different ways, by setting different attributes such as the colors, line_style, stroke_width etc.
Ability to specify a marker at each point passed to the line. The marker can be a shape which is at the data points between which the line is interpolated and can be set through the markers attribute
The Lines object has the following attributes
| Attribute |  Description | Default Value  |
|:-:|---|:-:|
|  colors | Sets the color of each line, takes as input a list of any RGB, HEX, or HTML color name  | CATEGORY10  |
| opacities  | Controls the opacity of each line, takes as input a real number between 0 and 1  | 1.0  |
| stroke_width  | Real number which sets the width of all paths  | 2.0  |
| line_style  | Specifies whether a line is solid, dashed, dotted or both dashed and dotted  | 'solid'  |
| interpolation  | Sets the type of interpolation between two points  | 'linear'  |
| marker  | Specifies the shape of the marker inserted at each data point  | None  |
| marker_size  | Controls the size of the marker, takes as input a non-negative integer  | 64  |
|close_path| Controls whether to close the paths or not | False |
|fill| Specifies in which way the paths are filled. Can be set to one of {'none', 'bottom', 'top', 'inside'}| None |
|fill_colors| List that specifies the fill colors of each path | [] |
| Data Attribute |  Description | Default Value  |
|x |abscissas of the data points | array([]) |
|y |ordinates of the data points | array([]) |
|color | Data according to which the Lines will be colored. Setting it to None defaults the choice of colors to the colors attribute | None |
To explore more features, run the following lines of code:
python
from bqplot import Lines
?Lines
or visit the Lines documentation page
Let's explore these features one by one
We begin by importing the modules that we will need in this example
End of explanation
security_1 = np.cumsum(np.random.randn(150)) + 100.0
security_2 = np.cumsum(np.random.randn(150)) + 100.0
Explanation: Random Data Generation
End of explanation
sc_x = LinearScale()
sc_y = LinearScale()
line = Lines(x=np.arange(len(security_1)), y=security_1, scales={"x": sc_x, "y": sc_y})
ax_x = Axis(scale=sc_x, label="Index")
ax_y = Axis(scale=sc_y, orientation="vertical", label="y-values of Security 1")
Figure(marks=[line], axes=[ax_x, ax_y], title="Security 1")
Explanation: Basic Line Chart
Using the bqplot, object oriented API, we can generate a Line Chart with the following code snippet:
End of explanation
line.colors = ["DarkOrange"]
Explanation: The x attribute refers to the data represented horizontally, while the y attribute refers the data represented vertically.
We can explore the different attributes by changing each of them for the plot above:
End of explanation
# The opacity allows us to display the Line while featuring other Marks that may be on the Figure
line.opacities = [0.5]
line.stroke_width = 2.5
Explanation: In a similar way, we can also change any attribute after the plot has been displayed to change the plot. Run each of the cells below, and try changing the attributes to explore the different features and how they affect the plot.
End of explanation
line.fill = "bottom"
line.fill_opacities = [0.2]
line.line_style = "dashed"
line.interpolation = "basis"
Explanation: To switch to an area chart, set the fill attribute, and control the look with fill_opacities and fill_colors.
End of explanation
line.marker = "triangle-down"
Explanation: While a Lines plot allows the user to extract the general shape of the data being plotted, there may be a need to visualize discrete data points along with this shape. This is where the markers attribute comes in.
End of explanation
# Here we define the dates we would like to use
dates = date_range(start="01-01-2007", periods=150)
dt_x = DateScale()
sc_y = LinearScale()
time_series = Lines(x=dates, y=security_1, scales={"x": dt_x, "y": sc_y})
ax_x = Axis(scale=dt_x, label="Date")
ax_y = Axis(scale=sc_y, orientation="vertical", label="Security 1")
Figure(marks=[time_series], axes=[ax_x, ax_y], title="A Time Series Plot")
Explanation: The marker attributes accepts the values square, circle, cross, diamond, square, triangle-down, triangle-up, arrow, rectangle, ellipse. Try changing the string above and re-running the cell to see how each marker type looks.
Plotting a Time-Series
The DateScale allows us to plot time series as a Lines plot conveniently with most date formats.
End of explanation
x_dt = DateScale()
y_sc = LinearScale()
Explanation: Plotting Multiples Sets of Data with Lines
The Lines mark allows the user to plot multiple y-values for a single x-value. This can be done by passing an ndarray or a list of the different y-values as the y-attribute of the Lines as shown below.
End of explanation
dates_new = date_range(start="06-01-2007", periods=150)
securities = np.cumsum(np.random.randn(150, 10), axis=0)
positions = np.random.randint(0, 2, size=10)
# We pass the color scale and the color data to the lines
line = Lines(
    x=dates,
    y=[security_1, security_2],
    scales={"x": x_dt, "y": y_sc},
    labels=["Security 1", "Security 2"],
)
ax_x = Axis(scale=x_dt, label="Date")
ax_y = Axis(scale=y_sc, orientation="vertical", label="Security 1")
Figure(marks=[line], axes=[ax_x, ax_y], legend_location="top-left")
Explanation: We pass each data set as an element of a list. The colors attribute allows us to pass a specific color for each line.
End of explanation
line.x, line.y = [dates, dates_new], [security_1, security_2]
Explanation: Similarly, we can also pass multiple x-values for multiple sets of y-values
End of explanation
x_dt = DateScale()
y_sc = LinearScale()
col_sc = ColorScale(colors=["Red", "Green"])
dates_color = date_range(start="06-01-2007", periods=150)
securities = 100.0 + np.cumsum(np.random.randn(150, 10), axis=0)
positions = np.random.randint(0, 2, size=10)
# Here we generate 10 random price series and 10 random positions
# We pass the color scale and the color data to the lines
line = Lines(
    x=dates_color,
    y=securities.T,
    scales={"x": x_dt, "y": y_sc, "color": col_sc},
    color=positions,
    labels=["Security 1", "Security 2"],
)
ax_x = Axis(scale=x_dt, label="Date")
ax_y = Axis(scale=y_sc, orientation="vertical", label="Security 1")
Figure(marks=[line], axes=[ax_x, ax_y], legend_location="top-left")
Explanation: Coloring Lines according to data
The color attribute of a Lines mark can also be used to encode one more dimension of data. Suppose we have a portfolio of securities and we would like to color them based on whether we have bought or sold them. We can use the color attribute to encode this information.
End of explanation
line.color = None
Explanation: We can also reset the colors of the Line to their defaults by setting the color attribute to None.
End of explanation
sc_x = LinearScale()
sc_y = LinearScale()
patch = Lines(
    x=[
        [0, 2, 1.2, np.nan, np.nan, np.nan, np.nan],
        [0.5, 2.5, 1.7, np.nan, np.nan, np.nan, np.nan],
        [4, 5, 6, 6, 5, 4, 3],
    ],
    y=[
        [0, 0, 1, np.nan, np.nan, np.nan, np.nan],
        [0.5, 0.5, -0.5, np.nan, np.nan, np.nan, np.nan],
        [1, 1.1, 1.2, 2.3, 2.2, 2.7, 1.0],
    ],
    fill_colors=["orange", "blue", "red"],
    fill="inside",
    stroke_width=10,
    close_path=True,
    scales={"x": sc_x, "y": sc_y},
    display_legend=True,
)
Figure(marks=[patch], animation_duration=1000)
patch.opacities = [0.1, 0.2]
patch.x = [
    [2, 3, 3.2, np.nan, np.nan, np.nan, np.nan],
    [0.5, 2.5, 1.7, np.nan, np.nan, np.nan, np.nan],
    [4, 5, 6, 6, 5, 4, 3],
]
patch.close_path = False
Explanation: Patches
The fill attribute of the Lines mark allows us to fill a path in different ways, while the fill_colors attribute lets us control the color of the fill
End of explanation
<END_TASK>