MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / PyplotLineStyles

Function PyplotLineStyles

DemoPrograms/Demo_Matplotlib_Browser_Paned.py:212–263  ·  view source on GitHub ↗

========== Linestyles ========== This examples showcases different linestyles copying those of Tikz/PGF.

()

Source from the content-addressed store, hash-verified

210
211
212def PyplotLineStyles():
213 """
214 ==========
215 Linestyles
216 ==========
217
218 This examples showcases different linestyles copying those of Tikz/PGF.
219 """
220 import numpy as np
221 import matplotlib.pyplot as plt
222 from collections import OrderedDict
223 from matplotlib.transforms import blended_transform_factory
224
225 linestyles = OrderedDict(
226 [('solid', (0, ())),
227 ('loosely dotted', (0, (1, 10))),
228 ('dotted', (0, (1, 5))),
229 ('densely dotted', (0, (1, 1))),
230
231 ('loosely dashed', (0, (5, 10))),
232 ('dashed', (0, (5, 5))),
233 ('densely dashed', (0, (5, 1))),
234
235 ('loosely dashdotted', (0, (3, 10, 1, 10))),
236 ('dashdotted', (0, (3, 5, 1, 5))),
237 ('densely dashdotted', (0, (3, 1, 1, 1))),
238
239 ('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10))),
240 ('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))),
241 ('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))])
242
243 plt.figure(figsize=(10, 6))
244 ax = plt.subplot(1, 1, 1)
245
246 X, Y = np.linspace(0, 100, 10), np.zeros(10)
247 for i, (name, linestyle) in enumerate(linestyles.items()):
248 ax.plot(X, Y + i, linestyle=linestyle, linewidth=1.5, color='black')
249
250 ax.set_ylim(-0.5, len(linestyles) - 0.5)
251 plt.yticks(np.arange(len(linestyles)), linestyles.keys())
252 plt.xticks([])
253
254 # For each line style, add a text annotation with a small offset from
255 # the reference point (0 in Axes coords, y tick value in Data coords).
256 reference_transform = blended_transform_factory(ax.transAxes, ax.transData)
257 for i, (name, linestyle) in enumerate(linestyles.items()):
258 ax.annotate(str(linestyle), xy=(0.0, i), xycoords=reference_transform,
259 xytext=(-6, -12), textcoords='offset points', color="blue",
260 fontsize=8, ha="right", family="monospace")
261
262 plt.tight_layout()
263 return plt.gcf()
264
265
266def PyplotLinePolyCollection():

Callers

nothing calls this directly

Calls 1

plotMethod · 0.45

Tested by

no test coverage detected