Created
January 31, 2019 14:16
-
-
Save Hi-king/52f210dc181b858eca984dadd2d97209 to your computer and use it in GitHub Desktop.
seabornで破線プロット
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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