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

Function PyplotLineStyles

DemoPrograms/Demo_Matplotlib_Browser.py:210–261  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

plotMethod · 0.45

Tested by

no test coverage detected