Skip to content

Instantly share code, notes, and snippets.

@Hi-king
Created January 31, 2019 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hi-king/52f210dc181b858eca984dadd2d97209 to your computer and use it in GitHub Desktop.
Save Hi-king/52f210dc181b858eca984dadd2d97209 to your computer and use it in GitHub Desktop.
seabornで破線プロット
import numpy
import seaborn
import pandas
from matplotlib import pyplot
n = 100
x = numpy.linspace(0, 4, n)
y1 = numpy.sin(2 * numpy.pi * x)
y2 = numpy.cos(2 * numpy.pi * x)
data = []
for i in range(n):
data.append({
"x": i,
"label": "sin",
"y": y1[i]
})
data.append({
"x": i,
"label": "cos",
"y": y2[i]
})
data = pandas.DataFrame(data)
seaborn.lineplot(
data=data, x="x", y="y",
style="label", # labelによってstyleを変えるよ、とする。これがないとdashesが効かない
hue="label", # labelによって色を変えるよ
dashes=[(2, 2)] * len(data["label"].value_counts()) # labelの種類数分だけ破線スタイル(2,2)を用意
)
pyplot.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment