I’m attempting to plot the following dataframe such that “col2” is plotted with a dashed line.
fig = px.line(df, x='x', y=['col1', 'col2'], facet_col='location', color='history')
fig.show()
After reading the examples and API doc’s, I haven’t quite figured out how to use options like line_dash
, line_dash_sequence
, or line_dash_map
. I’ve also tried variations of the following but I can’t make the selector
select “col2” data:
fig = px.line(df, x='x', y=['col1', 'col2'], facet_col='location', color='history', width=1000)
fig.update_traces(patch={"line": {"dash": "dot"}}, selector={'name': 'col2'})
fig.show()
Here’s same test sample data:
import pandas as pd
import numpy as np
import plotly.express as px
def make_data(location='east', history=5, size=5, scale=1.0):
data = {
'x': [10*x for x in range(size)],
'col1': np.random.rand(5) * scale,
'col2': np.random.rand(5) * scale / 2,
'history': [history for x in range(size)],
'location': [location for x in range(size)]
}
return pd.DataFrame(data)
df1 = make_data()
df2 = make_data(location='west')
df = pd.concat([
make_data(),
make_data(location='west', history=10, scale=0.75),
make_data(location='central', history=15, scale=0.5)
])
fig = px.line(df, x='x', y=['col1', 'col2'], facet_col='location', color='history')
fig.show()
The dataframe looks like this:
The sample line plot looks like this:
I’d like “col2” in the sample plot to be dashed (or dotted). Is this possible with plotly express or do I need to resort to the plotly.graph_objs
? Thank you in advance for any tips or suggestions you can offer.