<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>「linestyle」タグの記事一覧Python Tech</title>
	<atom:link href="https://tech.nkhn37.net/tag/linestyle/feed/" rel="self" type="application/rss+xml" />
	<link>https://tech.nkhn37.net</link>
	<description>Python学習サイト</description>
	<lastBuildDate>Mon, 12 Jan 2026 20:59:41 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://tech.nkhn37.net/wp-content/uploads/2021/01/cropped-lion-normal-clear-1-32x32.png</url>
	<title>「linestyle」タグの記事一覧Python Tech</title>
	<link>https://tech.nkhn37.net</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【matplotlib】線の色や形状を変更する方法</title>
		<link>https://tech.nkhn37.net/matplotlib-color-linestyle/</link>
					<comments>https://tech.nkhn37.net/matplotlib-color-linestyle/#respond</comments>
		
		<dc:creator><![CDATA[naoki-hn]]></dc:creator>
		<pubDate>Sat, 25 Sep 2021 00:00:00 +0000</pubDate>
				<category><![CDATA[matplotlib]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[linestyle]]></category>
		<category><![CDATA[plot]]></category>
		<guid isPermaLink="false">https://tech.nkhn37.net/?p=1882</guid>

					<description><![CDATA[Pythonによるデータ分析をする際にグラフなどの可視化でよく利用されるmatplotlibで線の色や形状を変更する方法について解説します。 matplotlibで線の色や形状を変更する方法 matplotlibでグラフ [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Pythonによるデータ分析をする際にグラフなどの可視化でよく利用される<span class="marker"><strong>matplotlib</strong></span>で<span class="marker"><strong>線の色や形状を変更する方法</strong></span>について解説します。</p>



<h2 class="wp-block-heading jinr-heading d--bold">matplotlibで線の色や形状を変更する方法</h2>



<p class="wp-block-paragraph">matplotlibでグラフ描画をしている際には、線の色や形状を変更したくなることがよくあります。本記事ではmatplotlibにおけるplotの描画で線の色や形状を変更する方法を紹介します。</p>



<h3 class="wp-block-heading jinr-heading d--bold" id="線の色を変更する方法">線の色を変更する方法</h3>



<p class="wp-block-paragraph">matplotlibで描画する線の色を変更するには、plotメソッドの<span class="marker"><strong>color</strong></span>引数に変更したい色の情報を指定します。</p>



<p class="wp-block-paragraph">以下にいくつかの色の指定方法を示します。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import matplotlib.pyplot as plt
import numpy as np

plt.style.use('seaborn-whitegrid')

x = np.linspace(0, 10, 100)

# 色を文字列で指定する。
plt.plot(x, x, color='red')
# 色を短縮文字列で指定する
plt.plot(x, x+1, color='b')
# グレースケールの範囲で指定する (0~1)
plt.plot(x, x+2, color='0.5')
# 16進数のカラーコードで指定する
plt.plot(x, x+3, color='#ff6c00')
# HTMLのカラーネームで指定する
plt.plot(x, x+4, color='darkgreen')

plt.show()</pre>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img fetchpriority="high" decoding="async" width="642" height="546" src="https://tech.nkhn37.net/wp-content/uploads/2021/09/image-10.png" alt="matplotlib plot color" class="wp-image-1890" srcset="https://tech.nkhn37.net/wp-content/uploads/2021/09/image-10.png 642w, https://tech.nkhn37.net/wp-content/uploads/2021/09/image-10-300x255.png 300w" sizes="(max-width: 642px) 100vw, 642px" /></figure>
</div>


<p class="wp-block-paragraph">色を指定する場合には、以下に示すようにいくつかの指定方法があります。</p>



<figure class="wp-block-table"><table><thead><tr><th>指定方法</th><th>内容</th></tr></thead><tbody><tr><td>色を文字列で指定 </td><td>&#8216;red&#8217; (赤), &#8216;blue&#8217; (青), &#8216;green&#8217; (緑)などの文字列で指定します。</td></tr><tr><td>色を短縮した文字列で指定す</td><td>&#8216;r&#8217; (赤), &#8216;b&#8217; (青), &#8216;g&#8217; (緑)など、色を短縮した文字列で指定します。</td></tr><tr><td>グレースケールの範囲で指定</td><td>0~1のグレースケールの範囲で指定します。引数に指定する際には&#8217;0.5&#8217;のように文字列として指定します。</td></tr><tr><td>16進数のカラーコードで指定</td><td>&#8216;#ff6c00&#8217; (鮮やかな赤みの橙)のように16進数のカラーコードで指定します。</td></tr><tr><td>HTMLのカラーネームで指定</td><td>&#8216;darkgreen&#8217;のようにHTMLで定義されているカラーネームで指定します。</td></tr></tbody></table></figure>



<h3 class="wp-block-heading jinr-heading d--bold" id="線の形状を変更する方法">線の形状を変更する方法</h3>



<p class="wp-block-paragraph">matplotlibで描画する線の形状を変更するには、plotメソッドの<span class="marker"><strong>linestyle</strong></span>引数に変更したい形状の情報を指定します。</p>



<p class="wp-block-paragraph">以下にいくつかの線の形状の指定方法を示します。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import matplotlib.pyplot as plt
import numpy as np

plt.style.use('seaborn-whitegrid')

x = np.linspace(0, 10, 100)

# ===== 線のスタイルを変更する
# 通常の線で表示する
plt.plot(x, x, linestyle='solid')
# 点線で表示する
plt.plot(x, x+1, linestyle='dashed')
# 点線+ドットの線で表示する
plt.plot(x, x+2, linestyle='dashdot')
# ドットの線で表示する
plt.plot(x, x+3, linestyle='dotted')

# ===== 省略形で指定する
# 通常の線で表示する(=solid)
plt.plot(x, x+4, linestyle='-')
# 点線で表示する(=dashed)
plt.plot(x, x+5, linestyle='--')
# 点線+ドットの線で表示する(=dashdot)
plt.plot(x, x+6, linestyle='-.')
# ドットの線で表示する(=dotted)
plt.plot(x, x+7, linestyle=':')

plt.show()</pre>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" width="642" height="546" src="https://tech.nkhn37.net/wp-content/uploads/2021/09/image-11.png" alt="matplotlib plot linestyle" class="wp-image-1892" srcset="https://tech.nkhn37.net/wp-content/uploads/2021/09/image-11.png 642w, https://tech.nkhn37.net/wp-content/uploads/2021/09/image-11-300x255.png 300w" sizes="(max-width: 642px) 100vw, 642px" /></figure>
</div>


<p class="wp-block-paragraph">線の形状を指定する場合には、以下に示すようにいくつかの指定方法があります。なお、文字列で指定する方法と記号を用いて指定する方法があります。 </p>



<figure class="wp-block-table"><table><thead><tr><th>指定方法</th><th>文字列で指定する方法</th><th>記号で指定する方法</th></tr></thead><tbody><tr><td>通常の線で表示</td><td>&#8216;solid&#8217;を指定します。</td><td>&#8216;-&#8216;を指定します。</td></tr><tr><td>点線で表示</td><td>&#8216;dashed&#8217;を指定します。</td><td>&#8216;&#8211;&#8216;を指定します。</td></tr><tr><td>点線+ドットの線で表示</td><td>&#8216;dashdot&#8217;を指定します。</td><td>&#8216;-.&#8217;を指定します。</td></tr><tr><td>ドットの線で表示</td><td>&#8216;dotted&#8217;を指定します。</td><td>&#8216;:&#8217;を指定します。</td></tr></tbody></table></figure>



<h3 class="wp-block-heading jinr-heading d--bold" id="線の色と形状を一括で変更する方法">線の色と形状を一括で変更する方法</h3>



<p class="wp-block-paragraph">線の色と形状を一括で変更する場合には、上記で紹介した色の指定と形状の指定をまとめて指定することができます。</p>



<p class="wp-block-paragraph">以下にいくつかの例を紹介します。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import matplotlib.pyplot as plt
import numpy as np

plt.style.use('seaborn-whitegrid')

x = np.linspace(0, 10, 100)

# ===== 腺の色と形状を一括で指定する
# 通常の線 + 青
plt.plot(x, x, '-b')
# 点線 + マゼンタ
plt.plot(x, x+1, '--m')
# 点線ドット + 黒
plt.plot(x, x+2, '-.k')
# ドット + 緑
plt.plot(x, x+3, ':g')

plt.show()</pre>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" width="642" height="546" src="https://tech.nkhn37.net/wp-content/uploads/2021/09/image-12.png" alt="matplotlib plot color&amp;linestyle" class="wp-image-1894" srcset="https://tech.nkhn37.net/wp-content/uploads/2021/09/image-12.png 642w, https://tech.nkhn37.net/wp-content/uploads/2021/09/image-12-300x255.png 300w" sizes="(max-width: 642px) 100vw, 642px" /></figure>
</div>


<p class="wp-block-paragraph">上記のように’-b&#8217;のように形状とまとめて指定することができます。また、順番を入れ替えて&#8217;b-&#8216;のようにしても同様の結果が得られます。</p>



<section class="wp-block-jinr-blocks-iconbox b--jinr-block b--jinr-iconbox"><div class="d--simple-iconbox6 ">
			<i class="jif jin-ifont-v2books" aria-hidden="true"></i>
			<div class="a--jinr-iconbox">
<p class="wp-block-paragraph"><code>matplotlib.pyplot.plot</code> の公式ドキュメントは<a href="https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html" target="_blank" rel="noreferrer noopener">こちら</a>を参照してください。</p>
</div>
		</div></section>



<section class="wp-block-jinr-blocks-simplebox b--jinr-block-container"><div class="b--jinr-block b--jinr-box d--heading-box8  "><div class="a--simple-box-title d--bold">ソースコード</div><div class="c--simple-box-inner">
<p class="wp-block-paragraph">上記で紹介しているソースコードについては <a href="https://github.com/nkhn37/python-tech-sample-source/tree/main/python-data-analysis/matplotlib/plot" target="_blank" rel="noreferrer noopener">GitHub</a> にて公開しています。参考にしていただければと思います。</p>
</div></div></section>


<section class="b--jinr-block b--jinr-blogcard d--blogcard-hover-up d--blogcard-style1 d--blogcard-mysite t--round "><div class="a--blogcard-label ef">あわせて読みたい</div><a class="o--blogcard-link t--round" href="https://tech.nkhn37.net/python-tech-summary-page/"><div class="c--blogcard-image"><img decoding="async" class="a--blogcard-img-src" width="128" height="72" src="https://tech.nkhn37.net/wp-content/uploads/2024/08/Python-Tech-Pythonプログラミングガイド_new1-640x360.jpg" alt="【Python Tech】プログラミングガイド" /></div><div class="a--blogcard-title d--bold">【Python Tech】プログラミングガイド</div></a></section>

]]></content:encoded>
					
					<wfw:commentRss>https://tech.nkhn37.net/matplotlib-color-linestyle/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Disk: Enhanced  を使用したページ キャッシュ

Served from: tech.nkhn37.net @ 2026-07-04 09:31:28 by W3 Total Cache
-->