Python:Plotting/Markers
Jump to navigation
Jump to search
This is a sandbox with an interactive script (if run on your own computer) to see what different markers will look like under different conditions. If the figure window is too large or small on your computer, change the "scale" value on line 20. If the font size is no good, change the "FS" value on line 22 (larger FS means larger relative font).
The Script
"""
colors_markers_fancy.py
Version 0.1
Michael R. Gustafson II
With lots of assistance from:
https://matplotlib.org/stable/gallery/widgets/slider_demo.html
"""
# %% Imports
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons
import tkinter as tk
# %% Initial figure window setup
root = tk.Tk()
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
screen_dpi = root.winfo_fpixels('1i')
scale = 2
L = scale * 2/3*screen_height/screen_dpi
FS = 1
fig, ax = plt.subplots(1, 1, num=1, clear=True)
fig.set_size_inches(L, L, forward=True)
mh, = ax.plot(0, 0, marker=".", mfc="k", mec="k", ms=50, mew=1)
ax.set(xlim=(-1,1), ylim=(-1,1), xticks=(), yticks=())
ax.margins(x=0)
fig.tight_layout()
fig.subplots_adjust(left=0.2, bottom=0.3, right=0.9)
# %% Axes for widgets
sbg = 'lightgray'
axmkrf = fig.add_axes([0.1, 0.2, 0.3, 0.03], fc=sbg, title="Face")
axredf = fig.add_axes([0.1, 0.15, 0.3, 0.03], fc=sbg)
axgrnf = fig.add_axes([0.1, 0.1, 0.3, 0.03], fc=sbg)
axbluf = fig.add_axes([0.1, 0.05, 0.3, 0.03], fc=sbg)
axmkre = fig.add_axes([0.6, 0.2, 0.3, 0.03], fc=sbg, title="Edge")
axrede = fig.add_axes([0.6, 0.15, 0.3, 0.03], fc=sbg)
axgrne = fig.add_axes([0.6, 0.1, 0.3, 0.03], fc=sbg)
axblue = fig.add_axes([0.6, 0.05, 0.3, 0.03], fc=sbg)
axmkr = fig.add_axes([0.025, 0.3, 0.1, 0.6], fc=sbg)
axreset = fig.add_axes([0.025, 0.93, 0.1, 0.04])
# %% Widgets
smkrf = Slider(axmkrf, 'Size', 1, L*30, valinit=50, valstep=1, color='k')
sredf = Slider(axredf, 'Red', 0, 1, valinit=0, color='r')
sgrnf = Slider(axgrnf, 'Green', 0, 1, valinit=0, color='g')
sbluf = Slider(axbluf, 'Blue', 0, 1, valinit=0, color='b')
smkre = Slider(axmkre, 'Size', 1, L*3, valinit=1, valstep=1, color='k')
srede = Slider(axrede, 'Red', 0, 1, valinit=0, color='r')
sgrne = Slider(axgrne, 'Green', 0, 1, valinit=0, color='g')
sblue = Slider(axblue, 'Blue', 0, 1, valinit=0, color='b')
rbmkr = RadioButtons(axmkr, list('.,ov^<>12348spP*hH+xXDd|_'), active=0)
breset = Button(axreset, 'Reset', color=sbg, hovercolor='0.975')
sliders = [smkrf, sredf, sgrnf, sbluf, smkre, srede, sgrne, sblue]
for sv in sliders:
sv.label.set_size(L*FS)
for circ in rbmkr.circles:
circ.width = 0.12
cenx, ceny = circ.center
new_center = (0.25, ceny)
circ.center = new_center
for label in rbmkr.labels:
label._x += 0.25
label.set_size(L*FS)
axmkrf.title.set_size(L*FS)
axmkre.title.set_size(L*FS)
breset.label.set_size(L*FS)
# %%
def update(val):
rgbf = (sredf.val, sgrnf.val, sbluf.val)
rgbe = (srede.val, sgrne.val, sblue.val)
sredf.poly.set_facecolor((sredf.val, 0, 0))
sgrnf.poly.set_facecolor((0, sgrnf.val, 0))
sbluf.poly.set_facecolor((0, 0, sbluf.val))
srede.poly.set_facecolor((srede.val, 0, 0))
sgrne.poly.set_facecolor((0, sgrne.val, 0))
sblue.poly.set_facecolor((0, 0, sblue.val))
mh.set(mfc=rgbf, mec=rgbe, ms=smkrf.val, mew=smkre.val, marker=rbmkr.value_selected)
fig.canvas.draw_idle()
def reset(event):
for sv in sliders:
sv.reset()
rbmkr.set_active(0)
for sv in sliders:
sv.on_changed(update)
rbmkr.on_clicked(update)
breset.on_clicked(reset)