Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

REORG: add a LineStyle class#18664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
brunobeltran wants to merge3 commits intomatplotlib:main
base:main
Choose a base branch
Loading
frombrunobeltran:line_style
Draft
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 23 additions & 69 deletionsexamples/lines_bars_and_markers/linestyles.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,74 +3,28 @@
Linestyles
==========

Simple linestyles can be defined using the strings "solid", "dotted", "dashed"
or "dashdot". More refined control can be achieved by providing a dash tuple
``(offset, (on_off_seq))``. For example, ``(0, (3, 10, 1, 15))`` means
(3pt line, 10pt space, 1pt line, 15pt space) with no offset. See also
`.Line2D.set_linestyle`.

*Note*: The dash style can also be configured via `.Line2D.set_dashes`
as shown in :doc:`/gallery/lines_bars_and_markers/line_demo_dash_control`
and passing a list of dash sequences using the keyword *dashes* to the
cycler in :doc:`property_cycle </tutorials/intermediate/color_cycle>`.
The Matplotlib `~mpl._enums.LineStyle` specifies the dash pattern used to draw
a given line. The simplest line styles can be accessed by name using the
strings "solid", "dotted", "dashed" and "dashdot" (or their short names, "-",
":", "--", and "-.", respectively).

The exact spacing of the dashes used can be controlled using the
'lines.*_pattern' family of rc parameters. For example,
:rc:`lines.dashdot_pattern` controls the exact spacing of dashed used whenever
the '-.' `~mpl._enums.LineStyle` is specified.

For more information about how to create custom `~mpl._enums.LineStyle`
specifications, see `the LineStyle docs <mpl._enums.LineStyle>`.

*Note*: For historical reasons, one can also specify the dash pattern for a
particular line using `.Line2D.set_dashes` as shown in
:doc:`/gallery/lines_bars_and_markers/line_demo_dash_control` (or by passing a
list of dash sequences using the keyword *dashes* to the cycler in
:doc:`property_cycle </tutorials/intermediate/color_cycle>`). This interface is
strictly less expressive, and we recommend using LineStyle (or the keyword
*linestyle* to the :doc:`property cycler
</tutorials/intermediate/color_cycle>`).
"""
import numpy as np
import matplotlib.pyplot as plt

linestyle_str = [
('solid', 'solid'), # Same as (0, ()) or '-'
('dotted', 'dotted'), # Same as (0, (1, 1)) or '.'
('dashed', 'dashed'), # Same as '--'
('dashdot', 'dashdot')] # Same as '-.'

linestyle_tuple = [
('loosely dotted', (0, (1, 10))),
('dotted', (0, (1, 1))),
('densely dotted', (0, (1, 1))),

('loosely dashed', (0, (5, 10))),
('dashed', (0, (5, 5))),
('densely dashed', (0, (5, 1))),

('loosely dashdotted', (0, (3, 10, 1, 10))),
('dashdotted', (0, (3, 5, 1, 5))),
('densely dashdotted', (0, (3, 1, 1, 1))),

('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))),
('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10))),
('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))]


def plot_linestyles(ax, linestyles, title):
X, Y = np.linspace(0, 100, 10), np.zeros(10)
yticklabels = []

for i, (name, linestyle) in enumerate(linestyles):
ax.plot(X, Y+i, linestyle=linestyle, linewidth=1.5, color='black')
yticklabels.append(name)

ax.set_title(title)
ax.set(ylim=(-0.5, len(linestyles)-0.5),
yticks=np.arange(len(linestyles)),
yticklabels=yticklabels)
ax.tick_params(left=False, bottom=False, labelbottom=False)
ax.spines[:].set_visible(False)

# For each line style, add a text annotation with a small offset from
# the reference point (0 in Axes coords, y tick value in Data coords).
for i, (name, linestyle) in enumerate(linestyles):
ax.annotate(repr(linestyle),
xy=(0.0, i), xycoords=ax.get_yaxis_transform(),
xytext=(-6, -12), textcoords='offset points',
color="blue", fontsize=8, ha="right", family="monospace")


ax0, ax1 = (plt.figure(figsize=(10, 8))
.add_gridspec(2, 1, height_ratios=[1, 3])
.subplots())

plot_linestyles(ax0, linestyle_str[::-1], title='Named linestyles')
plot_linestyles(ax1, linestyle_tuple[::-1], title='Parametrized linestyles')
from matplotlib._enums import LineStyle

plt.tight_layout()
plt.show()
LineStyle.demo()
4 changes: 4 additions & 0 deletionslib/matplotlib/_api/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -211,3 +211,7 @@ def warn_external(message, category=None):
break
frame = frame.f_back
warnings.warn(message, category, stacklevel)


def is_string_like(x):
return isinstance(x, (str, bytes, bytearray))
Loading

[8]ページ先頭

©2009-2025 Movatter.jp