def create_plot(time_data, title=''): start_time, xlabels, xlabels_sec = time_data fig, ax1 = interactive_subplots(figsize=(15, 9), constrained_layout=False) fig.marker_enable() def xdata_to_timestamp(sec): dt = start_time + datetime.timedelta(seconds=sec) return dt.strftime('%m/%d %H:%M') ax1.marker_set_params(xformat=xdata_to_timestamp, xreversed=False, show_xlabel=True) ax1.grid(linewidth=0.5, linestyle='-') ax1.set_title(title) ax1.set_xticks(xlabels_sec) ax1.set_xticklabels(xlabels) ax1.tick_params(labelsize='small') ax1.set_ylabel('PM2.5 ($\mu g / m^3$)') ax1.axhspan(0, 12, color='green', alpha=0.3) ax1.axhspan(12, 35, color='yellow', alpha=0.3) ax1.axhspan(35, 55, color='orange', alpha=0.35) ax1.axhspan(55, 150, facecolor='red', alpha=0.3) ax1.axhspan(150, 250, facecolor='purple', alpha=0.3) ax1.axhspan(250, 500, facecolor='maroon', alpha=0.3) return ax1
def __init__(self, site, days=3): icon = dir_ / 'icons/location.png' self.fig, (self.ax1, self.ax2) = interactive_subplots(2, 1, figsize=(20, 10), constrained_layout=True, icon=str(icon), title='Weather History') self.site = site self.days = days self.qapp = self.fig.qapp self.app = self.fig.app self.par1 = self.ax1.twinx() self.par2 = self.ax2.twinx() self.fig.marker_enable(show_xlabel=True, top_axes=(self.ax1, self.ax2)) self.ax2.marker_link(self.ax1) self.app.add_toolbar_actions( (dir_ / 'icons/location.png', 'Location', 'Set Station', self.set_station), (dir_ / 'icons/refresh.png', 'Update', 'Update', self.plot)) self.app.showMaximized() self.plot(site)
from markerplot import interactive_subplots dir_ = Path(__file__).parent #matplotlib.use('Qt4Agg') def xdata_to_theta(x, y, **kwargs): return '{:.3f}\n$\\theta$={:.3f}'.format(y, x * (180 / np.pi)) fig, axes = interactive_subplots(1, 1, subplot_kw=dict(polar=True), show_xlabel=True, yformat=xdata_to_theta, wrap=True, show_xline=True) axes.set_thetamin(-180) axes.set_thetamax(180) axes.set_theta_direction(-1) axes.set_theta_zero_location("N") axes.set_thetagrids(np.hstack( (np.arange(0, 180 + 30, 30), (np.arange(30, 180, 30) * -1)[::-1])), fontsize='small') # print(axes.InvertedPolarTransform(axes).transform) # print(axes.transData.transform((0,1.5))) #print(axes.__dict__)
from pathlib import Path import matplotlib import matplotlib.pyplot as plt import numpy as np #from fig2pptx import fig2pptx #import rftools import markerplot from markerplot import interactive_subplots from matplotlib import ticker dir_ = Path(__file__).parent fig, (ax1, ax2, ax3) = interactive_subplots(3, 1, figsize=(10,5), constrained_layout=True, dpi=100, show_xlabel=True, show_ylabel=True, link_all=False) ax1.grid(linewidth=0.5, linestyle='-') ax2.grid(linewidth=0.5, linestyle='-') ax3.grid(linewidth=0.5, linestyle='-') #fig.marker_enable(show_xline=True, show_xlabel=True, wrap=True, inherit_ticker=True, link_all=True) x1 = np.linspace(-2*np.pi, 2*np.pi, 100) l1 = ax1.plot(x1, np.sin(x1), label='sin') ax1.plot(x1, 2*x1, label='cos') ax2.plot(x1, np.sin(x1), label='sin', linewidth=1) ax3.plot(x1, np.cos(x1), label='cos') ax1.marker_add(xd=1.5) ax1.marker_add(xd=-1.5)
import markerplot from matplotlib import ticker from rfnetwork import Sparam, format_smithchart, db20 from markerplot import interactive_subplots dir_ = Path(__file__).parent matplotlib.use('Qt4Agg') tga2598 = Sparam(dir_ / r'data/TGA2598-SM.s2p') qpl9057 = Sparam(dir_ / r'data/QPL9057.s2p') def yformat(x,y,mxd): return '{:.3f}'.format(mxd) fig, ax1 = interactive_subplots(1, 1, figsize=(10,5), constrained_layout=True, yformat=yformat) format_smithchart(ax1, admittance=False, vswr_cirlce=True, lines=[5, 2, 1, 0.5, 0.2, 0]) line = ax1.plot(np.real(tga2598.sdata[:,0,0]), np.imag(tga2598.sdata[:,0,0]), marker_xd=tga2598.freq/1e9, label='tga2598') line = ax1.plot(np.real(qpl9057.sdata[:,0,0]), np.imag(qpl9057.sdata[:,0,0]), marker_xd=qpl9057.freq/1e9, label='qpl9057') fig, ax = interactive_subplots(1, 1, figsize=(10,5), constrained_layout=True, show_xlabel=True) ax.marker_link(ax1) ax.grid(True) ax.plot(tga2598.freq/1e9, db20(tga2598.sdata[:,0,0]), label='tga2598') ax.plot(qpl9057.freq/1e9, db20(qpl9057.sdata[:,0,0]), label='qpl9057')
from pathlib import Path import matplotlib import matplotlib.pyplot as plt import numpy as np from markerplot import interactive_subplots dir_ = Path(__file__).parent matplotlib.use('Qt4Agg') fig1, ax1 = interactive_subplots(1, 1, constrained_layout=True, figsize=(10,5)) ax1.grid(linewidth=0.5, linestyle='-') fig2, ax2 = interactive_subplots(1, 1, constrained_layout=True, figsize=(10,5)) ax2.grid(linewidth=0.5, linestyle='-') par1 = ax1.twinx() ## bring ax1 to top instead of par1 print(id(ax1)) fig1.marker_enable(show_xline=True, show_xlabel=False, top_axes=ax1) fig2.marker_enable(show_xline=True, show_xlabel=False) ## link all markers between ax1 and ax2 (interactive only) ax1.marker_link(ax2) x1 = np.linspace(-2*np.pi, 2*np.pi, 100) x2 = np.linspace(-6*np.pi, 6*np.pi, 100)
from pathlib import Path import matplotlib import matplotlib.pyplot as plt import numpy as np from markerplot import interactive_subplots dir_ = Path(__file__).parent fig, (ax1, ax2) = interactive_subplots(2, 1, constrained_layout=True, dpi=100, figsize=(10,5)) ax1.grid(linewidth=0.5, linestyle='-') ax2.grid(linewidth=0.5, linestyle='-') par1 = ax1.twinx() par2 = ax2.twinx() fig.marker_enable(show_xline=True, show_xlabel=False, link_all=True) x1 = np.linspace(-2*np.pi, 2*np.pi, 100) x2 = np.linspace(-6*np.pi, 6*np.pi, 100) ax1.plot(x1, np.sin(x1), label='sin(x)') par1.plot(x1, np.cos(x1), label='cos(x)') ax2.plot(x1, np.sin(x1), label='sin(x)') par2.plot(x1, np.cos(x1), label='cos(x)')
from pathlib import Path, PurePath import matplotlib import matplotlib.pyplot as plt import numpy as np #from fig2pptx import fig2pptx #import rftools import markerplot from markerplot import interactive_subplots from matplotlib import ticker from rfnetwork import Sparam dir_ = Path(__file__).parent fig, (ax1) = interactive_subplots(1, 1, figsize=(10, 5), constrained_layout=True) ax1.grid(linewidth=0.5, linestyle='-') plotted_sp = [] def drop_event_handler(text): p = Path(text) p = p.relative_to(r"file:\\") s = Sparam(str(p)) plotted_names = [sp.name for (sp, ax, lines) in plotted_sp] print(plotted_names, s.name) if s.name not in plotted_names: ax, lines = s.plot(axes=ax1, label=p.stem)