Skip to content

Commit

Permalink
Rename from pyqtmpl to pgmpl
Browse files Browse the repository at this point in the history
- There is already a way to embed matplotlib objects in pyqt.
- pyqtmpl sounds like a reference to pyqt GUIs with mpl widgets.
- pgmpl: pg = pyqtgraph; mpl = matplotlib
  • Loading branch information
eldond committed Apr 27, 2018
1 parent f04ef7b commit 5124de7
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 79 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PyQtMpl
# PgMpl
A set of wrappers to allow calling of pyqtgraph functions with matplotlib syntax

## Motivation:
Expand All @@ -8,9 +8,9 @@ Also, some projects may have a large number of Matplotlib based scripts.
These wrappers are intended to allow a script based on Matplotlib to be easily changed to PyQtGraph for faster development, then changed back to Matplotlib for a publication quality final product.

## Usage:
Import methods like plot from PyQtMpl instead of from Matplotlib while developing, then switch back to Matplotlib.
PyQtMpl contains submodules named for the Matplotlib submodules they imitate, like pyplot, figure, and axes.
Hopefully, you can get started by just changing import statements in your script.
Import methods like plot from PgMpl instead of from Matplotlib while developing, then switch back to Matplotlib.
PgMpl contains submodules named for the Matplotlib submodules they imitate, like pyplot, figure, and axes.
Hopefully, you can get started by just changing import statements in your script (you may also need to start the `QApplication` event loop).

## Examples and demonstrations:
examples.py is executable and will open a set of demonstration plots if called from the command line.
20 changes: 10 additions & 10 deletions examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# # -*- coding: utf-8 -*-

"""
Demonstrations and examples of pyqtmpl usage
Demonstrations and examples of pgmpl usage
"""

# Basic imports
Expand All @@ -17,10 +17,10 @@
# Plotting imports
import pyqtgraph as pg

# pyqtmpl
import pyqtmpl
import pyqtmpl.pyplot as plt
from pyqtmpl.tracking import tracker
# pgmpl
import pgmpl
import pgmpl.pyplot as plt
from pgmpl.tracking import tracker

pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')
Expand Down Expand Up @@ -91,16 +91,16 @@ def short_demo():


if __name__ == '__main__':
print('pyqtmpl examples...')
pyqtmpl.set_debug(1)
print('pgmpl examples...')
pgmpl.set_debug(1)
a = short_demo()
b = demo_plot()
# a[0].close() # This is not needed, but it makes testing faster.
tracker.status()
# Start Qt event loop unless running in interactive mode or using pyside.
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
print('Starting event loop for pyqtmpl examples...')
pyqtmpl.app.exec_()
print('Starting event loop for pgmpl examples...')
pgmpl.app.exec_()
else:
print('Done with pyqtmpl examples.')
print('Done with pgmpl examples.')

8 changes: 4 additions & 4 deletions omfit_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
# Created by eldond at 2018 Apr 25 11:55

"""
This script demonstrates pyqtmpl usage within OMFIT.
This script demonstrates pgmpl usage within OMFIT.
Load this thing into the OMFIT by executing the following in the OMFIT command box (edit the path):
OMFIT['mpl_demo'] = OMFITpythonTask('/home/eldond/python_stuff/pyqtmpl/omfit_demo.py', modifyOriginal=True)
OMFIT['mpl_demo'] = OMFITpythonTask('/home/eldond/python_stuff/pgmpl/omfit_demo.py', modifyOriginal=True)
"""

from __future__ import print_function, division
import pyqtmpl as mpl
import pyqtmpl.pyplot as plt
import pgmpl as mpl
import pgmpl.pyplot as plt

print(mpl.__version__)
mpl.set_debug(True)
Expand Down
10 changes: 5 additions & 5 deletions pyqtmpl/__init__.py → pgmpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
import pyqtgraph as pg
from matplotlib import rcParams

# pyqtmpl imports
# pgmpl imports
from info import * # Defines __version__, etc.
from util import printd
from translate import color_translator

__all__ = ['figure', 'axes', 'pyplot', 'translate', 'examples', 'text']

# Handle debugging
if os.environ.get('PYQTMPL_DEBUG', None) is None:
os.environ['PYQTMPL_DEBUG'] = "0"
if os.environ.get('PGMPL_DEBUG', None) is None:
os.environ['PGMPL_DEBUG'] = "0"


def set_debug(enable=True):
os.environ['PYQTMPL_DEBUG'] = str(int(enable))
printd('pyqtmpl debugging set to {}'.format(str(int(enable))))
os.environ['PGMPL_DEBUG'] = str(int(enable))
printd('pgmpl debugging set to {}'.format(str(int(enable))))


# Setup style, etc.
Expand Down
10 changes: 5 additions & 5 deletions pyqtmpl/axes.py → pgmpl/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from cycler import cycler
from collections import defaultdict

# pyqtmpl
# pgmpl
from translate import plotkw_translator, color_translator, setup_pen_kw
from util import printd, tolist
from text import Text
Expand Down Expand Up @@ -94,7 +94,7 @@ def text(self, x, y, s, fontdict=None, withdash=False, **kwargs):
:return: Text instance
"""
if withdash:
warnings.warn(' pyqtmpl.Axes.text withdash=True keyword is not not handled (yet?)')
warnings.warn(' pgmpl.Axes.text withdash=True keyword is not not handled (yet?)')
text = Text(x, y, s, fontproperties=fontdict, **kwargs)
self.addItem(text)
return text
Expand Down Expand Up @@ -252,7 +252,7 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False, step=None, da
brush = color_translator(color=kwargs['color'], alpha=kwargs.get('alpha', None))
else:
brush = color_translator(color='b', alpha=kwargs.get('alpha', None))
printd(' pyqtmpl.axes.Axes.fill_between(): brush = {}, ekw = {}, setup_pen_kw(**ekw) = {}'.format(
printd(' pgmpl.axes.Axes.fill_between(): brush = {}, ekw = {}, setup_pen_kw(**ekw) = {}'.format(
brush, ekw, setup_pen_kw(**ekw)))

# Handle special keywords
Expand Down Expand Up @@ -333,7 +333,7 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):

class Legend:
"""
Post-generated legend for pyqtmpl.axes.Axes. This is not a direct imitation of Matplotlib's Legend as it has to
Post-generated legend for pgmpl.axes.Axes. This is not a direct imitation of Matplotlib's Legend as it has to
accept events from pyqtgraph. It also has to bridge the gap between Matplotlib style calling legend after plotting
and pyqtgraph style calling legend first.
Expand Down Expand Up @@ -419,7 +419,7 @@ def __call__(
printd(' custom legend call')
self.leg = self.ax.addLegend()
# ax.addLegend modifies ax.legend, so we have to put it back in order to
# preserve a reference to pyqtmpl.axes.Legend.
# preserve a reference to pgmpl.axes.Legend.
self.ax.legend = self

if handles is None:
Expand Down
2 changes: 1 addition & 1 deletion pyqtmpl/figure.py → pgmpl/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Plotting imports
import pyqtgraph as pg

# pyqtmpl
# pgmpl
from tracking import tracker
from translate import plotkw_translator
from axes import Axes
Expand Down
2 changes: 1 addition & 1 deletion pyqtmpl/info.py → pgmpl/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# # -*- coding: utf-8 -*-

"""
Information for the pyqtmpl module.
Information for the pgmpl module.
This would normally go in __init__.py, but importing __init__ in setup.py to get info causes a segfault during package
installation. So, this information is placed here and imported into __init__.py and into setup.py.
Expand Down
6 changes: 3 additions & 3 deletions pyqtmpl/pyplot.py → pgmpl/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Calculation imports
import numpy as np

# pyqtmpl
# pgmpl
from tracking import tracker
from figure import Figure
from axes import Axes
Expand All @@ -22,8 +22,8 @@

def figure(*args, **kwargs):
"""
Imitates matplotlib.pyplot.figure, but creates a PyQtGraph window with the pyqtmpl.Figure class
:return: pyqtmpl.Figure instance
Imitates matplotlib.pyplot.figure, but creates a PyQtGraph window with the pgmpl.Figure class
:return: pgmpl.Figure instance
"""
return Figure(*args, **kwargs)

Expand Down
24 changes: 12 additions & 12 deletions pyqtmpl/text.py → pgmpl/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def __init__(
Color of text
:param verticalalignment: string {top | bottom | center | baseline}
:param horizontalalignment: string {left | center | right}
:param multialignment: (not implemented in pyqtmpl wrapper)
:param multialignment: (not implemented in pgmpl wrapper)
:param fontproperties: dict (not yet implemented)
:param rotation: scalar
Text angle in degrees. 0 is horizontal and upright
:param linespacing: (not implemented in pyqtmpl wrapper)
:param rotation_mode: (not implemented in pyqtmpl wrapper)
:param usetex: (not implemented in pyqtmpl wrapper)
:param wrap: (not yet implemented in pyqtmpl wrapper)
:param linespacing: (not implemented in pgmpl wrapper)
:param rotation_mode: (not implemented in pgmpl wrapper)
:param usetex: (not implemented in pgmpl wrapper)
:param wrap: (not yet implemented in pgmpl wrapper)
:param kwargs: dict
Other keywords
"""
Expand All @@ -69,21 +69,21 @@ def __init__(
self.setPos(x, y)

if multialignment is not None:
warnings.warn(' pyqtmpl.text.Text does not support multialignment keyword')
warnings.warn(' pgmpl.text.Text does not support multialignment keyword')
if rotation_mode is not None:
warnings.warn(' pyqtmpl.text.Text does not support rotation_mode keyword')
warnings.warn(' pgmpl.text.Text does not support rotation_mode keyword')
if usetex is not None:
warnings.warn(' pyqtmpl.text.Text does not support usetex keyword')
warnings.warn(' pgmpl.text.Text does not support usetex keyword')
if linespacing is not None:
warnings.warn(' pyqtmpl.text.Text does not support linespacing keyword')
warnings.warn(' pgmpl.text.Text does not support linespacing keyword')

if wrap is not None:
warnings.warn(' pyqtmpl.text.Text does not support wrap keyword yet (may be possible later)')
warnings.warn(' pgmpl.text.Text does not support wrap keyword yet (may be possible later)')
if fontproperties is not None:
warnings.warn(' pyqtmpl.text.Text does not handle font changes yet (to be implemented later)')
warnings.warn(' pgmpl.text.Text does not handle font changes yet (to be implemented later)')

if len(kwargs.keys()):
warnings.warn(' pyqtmpl.text.Text got unhandled kwargs: {}'.format(kwargs.keys()))
warnings.warn(' pgmpl.text.Text got unhandled kwargs: {}'.format(kwargs.keys()))

def __call__(self):
return self
2 changes: 1 addition & 1 deletion pyqtmpl/tracking.py → pgmpl/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from __future__ import print_function, division
import warnings

# pyqtmpl
# pgmpl
from util import printd


Expand Down
2 changes: 1 addition & 1 deletion pyqtmpl/translate.py → pgmpl/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from matplotlib.colors import colorConverter
to_rgba = colorConverter.to_rgba

# pyqtmpl imports
# pgmpl imports
from util import printd


Expand Down
2 changes: 1 addition & 1 deletion pyqtmpl/util.py → pgmpl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def printd(*args, **kw):
:param level: int
Debugging level
"""
debug = os.environ.get('PYQTMPL_DEBUG', "0")
debug = os.environ.get('PGMPL_DEBUG', "0")
if int(debug) >= kw.pop('level', 1):
print(*args)

Expand Down
28 changes: 14 additions & 14 deletions pyqtmpl_vs_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
The single quotes on this docstring are a way to trick bash
https://www.rodneybeede.com/How_to_use_command_line_arguments_with_shebang__usr_bin_env_python.html
To use this script, do ./pyqtmpl_vs_mpl for matplotlib or ./pyqtmpl_vs_mpl pg for pyqtmpl.
To use this script, do ./pgmpl_vs_mpl for matplotlib or ./pgmpl_vs_mpl pg for pgmpl.
This script should work if copied outside of the pyqtmpl folder
This script should work if copied outside of the pgmpl folder
'''
# # -*- coding: utf-8 -*-

Expand All @@ -22,15 +22,15 @@

print(sys.argv)
if len(sys.argv) > 1:
use_pyqtmpl = sys.argv[1].lower() in ['pyqtmpl', '1', 'pg', 'p']
use_pgmpl = sys.argv[1].lower() in ['pgmpl', '1', 'pg', 'p']
else:
use_pyqtmpl = False
use_pgmpl = False

if use_pyqtmpl:
if use_pgmpl:
from PyQt4 import QtGui
import pyqtmpl as mpl
import pyqtmpl.pyplot as plt
import pyqtmpl
import pgmpl as mpl
import pgmpl.pyplot as plt
import pgmpl

else:
import matplotlib as mpl
Expand Down Expand Up @@ -69,23 +69,23 @@ def demo_plot():
axs[1, 0].axvline(np.mean(x), linestyle=':', color='k')
axs[1, 0].axhline(np.mean(y1), linestyle='-', color='k')

if not use_pyqtmpl:
if not use_pgmpl:
fig.show()

return fig, axs


if __name__ == '__main__':
if os.environ.get('PYQTMPL_DEBUG', None) is None:
os.environ['PYQTMPL_DEBUG'] = "1"
if use_pyqtmpl:
app = pyqtmpl.app # QtGui.QApplication(sys.argv)
if os.environ.get('PGMPL_DEBUG', None) is None:
os.environ['PGMPL_DEBUG'] = "1"
if use_pgmpl:
app = pgmpl.app # QtGui.QApplication(sys.argv)
else:
app = None
b = demo_plot()
# Start Qt event loop unless running in interactive mode or using pyside.
if (app is not None) and ((sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION')):
app.exec_()
if not use_pyqtmpl:
if not use_pgmpl:
plt.ioff() # https://stackoverflow.com/a/38592888/6605826
plt.show()
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import glob
import os

# pyqtmpl imports
from pyqtmpl.info import *
# pgmpl imports
from pgmpl.info import *


# http://python-packaging.readthedocs.io/en/latest/dependencies.html
Expand All @@ -19,18 +19,18 @@
required = filter(None, map(lambda x: x.split("#")[0].strip(), f.read().splitlines()))

print required
print('pyqtmpl setup.py...')
print('pgmpl setup.py...')

# Run setup
setup(
name='pyqtmpl',
name='pgmpl',
version=__version__,
description='Wrapper for calling PyQtGraph with Matplotlib syntax',
url='https://github.com/eldond/pyqtmpl',
url='https://github.com/eldond/pgmpl',
author=__maintainer__,
author_email=__email__,
packages=[
'pyqtmpl',
'pgmpl',
],
keywords='plotting plot matplotlib pyqtgraph',
install_requires=required,
Expand Down
Loading

7 comments on commit 5124de7

@eldond
Copy link
Owner Author

@eldond eldond commented on 5124de7 Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @logan-nc @orso82 I figured it was still early enough that I could get away with this. I renamed the repo, too.

@orso82
Copy link
Collaborator

@orso82 orso82 commented on 5124de7 Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! This is one of those things that is best to do sooner rather than later

@eldond
Copy link
Owner Author

@eldond eldond commented on 5124de7 Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With that in mind, please comment now if you think the name is still not good enough. I definitely don't want to change it after more people start noticing.

@logan-nc
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. I know a lot of converter modules use 2s, like pqg2mpl or mpl2pgq.

@eldond
Copy link
Owner Author

@eldond eldond commented on 5124de7 Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, good point. But is this what you'd call a converter module? It's not like it takes a mpl script and re-writes it for pg the way ps2pdf creates a pdf file given a ps. This here is just a translation layer.

@orso82 do you like mpl2pg better as a name?

@logan-nc
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly. Just trying to brainstorm since you asked - it's totally your call.
I suppose matplotlib_like_wrappers_for_pyqtgraph is too long ;)

Really matploltib is already a similar thing for matlab type calls.... so you could cut out the middle man and call yours matgraphlib :P

@eldond
Copy link
Owner Author

@eldond eldond commented on 5124de7 Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, the tentative conclusion is: not worth another rename. But I'm willing to reconsider if someone has some strong motivation.

Please sign in to comment.