olgabot / prettyplotlib Goto Github PK
View Code? Open in Web Editor NEWPainlessly create beautiful matplotlib plots.
Home Page: olgabot.github.io/prettyplotlib
License: MIT License
Painlessly create beautiful matplotlib plots.
Home Page: olgabot.github.io/prettyplotlib
License: MIT License
Is it possible to use prettyplotlib to pretty up the output of dataframe.plot? I tried doing this
with ppl.pretty:
dataframe.plot()
The resulting plot had the ppl colors but all of the other chart junk, gridlines, etc were the same as the default.
Hi @olgabot. Do you plan on uploading a new release on PyPI soon? I would like to have "pip install prettyplotlib" fetch the code with the Python 3 compatibility changes, instead of having to point pip to the GitHub repo.
I see no images in the comparison with matplotlib.
Please add support for plt.errobar.
If I try to plot something in a pcolormesh
plot with prettyplottlib
in an IPython notebook, the plot is shown twice. I am plotting figures inline in the notebook and this behaviour occurs both if I start the notebook as:
ipython notebook --matplotlib=inline
Or if I include it via a %matplotlib
magic inside the notebook. Example:
%matplotlib inline
import prettyplotlib as ppl
import numpy as np
data = np.random.random((10,10))
ppl.pcolormesh(data)
Not sure why this is happening.. used python setup.py sdist upload
to send to PyPI, which did upload a source version, but that isn't getting pulled down by certain users for some reason.
The first three figures on the front page are linked incorrectly. Probably they should go to Examples-with-code instead of Examples-gallery.
In #13, @ilblackdragon mentioned that pip can sometimes fetch the wrong distribution file of prettyplotlib. More specifically
@ilblackdragon, is there a chance that the pip versions are different for your system-wide installation than the ones inside your virtualenvs?
@olgabot Is there a reason for a tarball built specifically for OS X 10.9? prettyplotlib has no extension modules that need to be built for any specific platform and is a pure Python package. I see that it's meant to be untarred at the root directory so that it unpacks into /usr/local/lib/python2.7/site-packages/prettyplotlib
, but this isn't even the right directory to unpack to for most OS X users since OS X uses the whole "Framework Python" layout (unless the user has explicitly installed a non-Framework Python via MacPorts or Homebrew). I'm not sure this extra tarball is helpful and it seems detrimental in the case of confusing pip on which tarball it should fetch.
Is there a reason why caps have been reintroduced in boxplot?
Suggestion for line 91:
plt.setp(bp['caps'], color='white')
Here is an example of what I am trying to do:
import prettyplotlib as ppl
import matplotlib.pyplot as plt
import numpy as np
x = 5 + np.linspace(-np.pi, np.pi, 100)
y = 2 + np.linspace(0, 2*np.pi, 100)
X, Y = np.meshgrid(x, y)
C = np.tanh(X) + np.cos(Y)
fig, ax = plt.subplots(1)
ppl.pcolormesh(fig, ax, X, Y, C)
#ax.axis('image')
but ppl
does not accept the standard pcolormesh
arguments (https://github.com/olgabot/prettyplotlib/blob/master/prettyplotlib/_pcolormesh.py#L34)
I can see fixing it by checking if the first three arguments are of type np.ndarray, and if so, using the third on as x
. Or, by having a kwarg like Qx
and Qy
that contains the coordinates to plot against, then pass those arrays to pcolormesh
like normal.
I have a notebook started with --pylab inline
and a script that looks like this:
import prettyplotlib as ppl
np.random.seed(12)
fig, ax = plt.subplots(1)
ppl.hist(ax, np.random.randn(1000))
But the output seems to render using the default matplotlib colours:
Am I doing something wrong, or is there a version incompatibility somewhere?
This is on Ubuntu 12.04, Python 3.4, and here is the output of pip --list
:
beautifulsoup4 (4.2.1)
Bottleneck (0.8.0)
brewer2mpl (1.4)
Cython (0.20.1)
deap (1.0.1)
distribute (0.6.49)
docutils (0.11)
fastcluster (1.1.13)
ipython (2.0.0)
Jinja2 (2.7.2)
lxml (3.3.5)
MarkupSafe (0.21)
matplotlib (1.3.1)
nose (1.3.1)
numexpr (2.4)
numpy (1.8.1)
numpydoc (0.5.dev)
pandas (0.13.1)
patsy (0.2.1)
pip (1.5.4)
prettyplotlib (0.1.7)
psycopg2 (2.5.2)
Pygments (1.6)
pymc (3.0)
pyparsing (2.0.2)
python-dateutil (2.2)
pytz (2014.2)
pyzmq (14.1.1)
scikit-learn (0.15-git)
scipy (0.13.3)
seaborn (0.3)
setuptools (0.6c11)
six (1.6.1)
Sphinx (1.2.2)
statsmodels (0.6.0)
sympy (0.7.5)
tables (3.1.1)
Theano (0.6.0)
tornado (3.2)
When I create a histogram with a log scale, the y-axis is too large to show the available data. If I add a limit using ax.set_ylim(0, 25)
, the graph still does not show any data.
import prettyplotlib as ppl
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(12)
fig, ax = plt.subplots(1)
ppl.hist(ax, np.random.randn(100), grid='y')
ax.set_yscale('log')
ax.set_ylim(0, 25)
plt.show()
need to change the following:
" edgecolor=ppl.almost_black,\n",
" edgecolor=ppl.colors.almost_black,\n",
"import matplotlib.pyplot as plt\n",
" ppl.remove_chartjunk(ax, ['top', 'right'])\n",
" ppl.utils.remove_chartjunk(ax, ['top', 'right'])\n",
Currently only importing prettyplolib will change mpl.rcParams defaults, so the following plots, even ones which were not produced with prettyplolib will have different defaults.
import matplotlib.pyplot as plt
from pandas import *
from numpy.random import randn
ts = Series(randn(1000), index=date_range('1/1/2000', periods=1000))
ts = ts.cumsum()
# plots normal plots
ts.plot()
plt.show()
import prettyplotlib
# plots changed plots
ts.plot()
plt.show()
[Edit: included example directly]
It would be nice if prettyplotlib would offer two ways to get the new defaults:
This would make it easier to use prettyplotlib in libraries
The vert
keyword argument in matplotlib makes the boxes horizontal when set to false. This isn't handled well by prettyplotlib as all of the labels and the spline retain their original positions.
When I try to install, I get the following error message:
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
This seems to be problem with the recently updated xcode. A temporary solution is given here (http://kaspermunck.github.io/2014/03/fixing-clang-error/). Would it be possible to implement it into prettypot?
Try e.g.
import numpy as np, matplotlib.pyplot as plt, prettyplotlib as ppl
f, (ax1, ax2) = plt.subplots(2)
ppl.hist(ax1, np.random.normal(size=(1e6,)), 500)
ax2.hist(np.random.normal(size=(1e6,)), 500)
plt.show()
I guess that the bars become totally invisible because they become thinner than the amount of whitespace ppl is trying to insert between them.
when having more than about 25 lables on the x-axis (say 50) is not handled properly(overlapping lables) or is there a command to fix it ?
Is there a way to change the default color set from ColorBrewer set 2 to something else (e.g. ColorBrewer set 1)?
Hi there,
As the title suggests, there is a minor typo in the setup.py file (line 13):
if sys.version_info[0] == 3:
REQUIREMENTS = open('requirments.txt', encoding='utf-8').readlines()
ImportError Traceback (most recent call last)
in ()
----> 1 import prettyplotlib
C:\Users\Feng\build\bdist.win-amd64\egg\prettyplotlib__init__.py in ()
C:\Users\Feng\build\bdist.win-amd64\egg\prettyplotlib_bar.py in ()
C:\Users\Feng\build\bdist.win-amd64\egg\prettyplotlib\utils.py in ()
D:\Python\Python27\lib\site-packages\matplotlib\pyplot.py in ()
22
23 import matplotlib
---> 24 import matplotlib.colorbar
25 from matplotlib import _pylab_helpers, interactive
26 from matplotlib.cbook import dedent, silent_list, is_string_like, is_numlike
D:\Python\Python27\lib\site-packages\matplotlib\colorbar.py in ()
27 import matplotlib.artist as martist
28 import matplotlib.cbook as cbook
---> 29 import matplotlib.collections as collections
30 import matplotlib.colors as colors
31 import matplotlib.contour as contour
D:\Python\Python27\lib\site-packages\matplotlib\collections.py in ()
21 import matplotlib.artist as artist
22 from matplotlib.artist import allow_rasterization
---> 23 import matplotlib.backend_bases as backend_bases
24 import matplotlib.path as mpath
25 from matplotlib import _path
D:\Python\Python27\lib\site-packages\matplotlib\backend_bases.py in ()
48
49 import matplotlib.tight_bbox as tight_bbox
---> 50 import matplotlib.textpath as textpath
51 from matplotlib.path import Path
52 from matplotlib.cbook import mplDeprecation
D:\Python\Python27\lib\site-packages\matplotlib\textpath.py in ()
9 from matplotlib.path import Path
10 from matplotlib import rcParams
---> 11 import matplotlib.font_manager as font_manager
12 from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
13 from matplotlib.ft2font import LOAD_TARGET_LIGHT
D:\Python\Python27\lib\site-packages\matplotlib\font_manager.py in ()
51 import matplotlib
52 from matplotlib import afm
---> 53 from matplotlib import ft2font
54 from matplotlib import rcParams, get_cachedir
55 from matplotlib.cbook import is_string_like
ImportError: numpy.core.multiarray failed to import
Hi,
When I try to run
colors = {nucleotide: ppl.set2[i] for i, nucleotide in enumerate(nucleotides)}
As shown in:
https://github.com/olgabot/prettyplotlib/wiki/Examples-with-code#bar-correctly-annotates-negative-values
I get an error:
AttributeError: 'module' object has no attribute 'set2'
I am not sure but I looked at the code and I think you are not importing it (since only bits of colors.py are imported and not the whole module).
It looks like with matplotlib 1.3.1 plotting doesn't pick up the right colors.
numpy==1.7.1
prettyplotlib==0.1.7
brewer2mpl==1.4
matplotlib==1.3.1
I'm looking at the example from https://github.com/olgabot/prettyplotlib/wiki/Examples-with-code#plot-lines-eg-time-series-with-a-legend
import prettyplotlib as ppl
import numpy as np
# prettyplotlib imports
import matplotlib.pyplot as plt
import matplotlib as mpl
from prettyplotlib import brewer2mpl
# Set the random seed for consistency
np.random.seed(12)
fig, ax = plt.subplots(1)
# Show the whole color range
for i in range(8):
y = np.random.normal(size=1000).cumsum()
x = np.arange(1000)
# For now, you need to specify both x and y :(
# Still figuring out how to specify just one
ppl.plot(ax, x, y, label=str(i), linewidth=0.75)
ppl.legend(ax)
fig.savefig('plot_prettyplotlib_default.png')
Creates the following image:
Installation with pip leads to an error:
$ pip install --upgrade prettyplotlib
Downloading/unpacking prettyplotlib from https://pypi.python.org/packages/source/p/prettyplotlib/prettyplotlib-0.1.5.tar.gz#md5=4de2eccf22f1bb8c52b07114d18182dd
Downloading prettyplotlib-0.1.5.tar.gz (697kB): 697kB downloaded
Running setup.py (path:/home/jgosmann/.virtualenvs/default/build/prettyplotlib/setup.py) egg_info for package prettyplotlib
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/home/jgosmann/.virtualenvs/default/build/prettyplotlib/setup.py", line 10, in <module>
LONG_DESCRIPTION = open('README.rst').read()
IOError: [Errno 2] No such file or directory: 'README.rst'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/home/jgosmann/.virtualenvs/default/build/prettyplotlib/setup.py", line 10, in <module>
LONG_DESCRIPTION = open('README.rst').read()
IOError: [Errno 2] No such file or directory: 'README.rst'
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /home/jgosmann/.virtualenvs/default/build/prettyplotlib
Storing debug log for failure in /home/jgosmann/.pip/pip.log
README.rst is indeed missing in the archive being downloaded.
I've modified bar and barh charts to support stacking and annotating stack values for my personal project. I can issue a pull request if you are interested in adding this support for bar charts.
The package description on PyPI doesn't look very nice (many escape sequences and some useless HTML code). Is there a way to get a cleaner description up there?
Hi,
Please add support for the easy creation of pretty pie charts.
Ideally for pie charts which could have more than 11 slices*.
Regards,
Sibin
* The maximum number of defined colors for any 'color map' of any 'color map type' is 11 ('Diverging' color map type supports 11 colors).
Suggest adding for
so that lines 403-405 become:
if grid is not None:
for g in grid:
assert g in ('x', 'y')
ax.grid(axis=g, color='white', linestyle='-', linewidth=0.5)
For a category, if there are equal values, space them apart equally.
Need to supply color=color so that it fills, otherwise get an empty rectangle. This is a bug related to matplotlib filling patches by default, which was turned off in the rcParams
:
# Default empty circle with a colored outline
mpl.rcParams['patch.facecolor'] = 'none'
mpl.rcParams['patch.edgecolor'] = set2[0]
When I try to run your scatter plot example (https://github.com/olgabot/prettyplotlib/wiki/Examples-with-code#scatter-points), I can only see green colors in all the points. I am not ablle to see all the different colors in the plot.
pydoc prettyplotlib.general
doesn't show any results because it thinks the subplots
and subplot2grid
functions are defined in the pyplot
module, as functools.wraps
has modified their __module__
attribute. Instead, I think only the __doc__
and __wrapped__
attributes should be set, either manually or using functools.update_wrapper
(setting __wrapped__
properly also sets the correct signature in pydoc).
The bar plots annotate all float data with 3 digits of precision. Is it possible to control this? Maybe have a new user defined parameter that can be used to set the precision of the data in case of floats.
Suggested by Phillip Guo so the objects can be further modified.
This is what I got from the installation through pip (and easy_install):
g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-2.7/src/ft2font.o build/temp.linux-x86_64-2.7/src/mplutils.o build/temp.linux-x86_64-2.7/CXX/IndirectPythonInterface.o build/temp.linux-x86_64-2.7/CXX/cxx_extensions.o build/temp.linux-x86_64-2.7/CXX/cxxsupport.o build/temp.linux-x86_64-2.7/CXX/cxxextensions.o -L/usr/local/lib -lfreetype -lstdc++ -lm -o build/lib.linux-x86_64-2.7/matplotlib/ft2font.so
building 'matplotlib._png' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC ->DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib__png_ARRAY_API -DPYCXX_ISO_CPP_LIB=1 -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/local/include -I/usr/include -I. -I/usr/include/python2.7 -c src/_png.cpp -o build/temp.linux-x86_64-2.7/src/_png.o
src/_png.cpp:10:20: fatal error: png.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
Rolling back uninstall of matplotlib
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;file='/tmp/pip_build_root/matplotlib/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-U3hamL-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/matplotlib
Storing debug log for failure in /home/hsuch/.pip/pip.log
I tried to look for png.h, and it looks like it is indeed missing in the downloaded tarball
I just installed prettyplotlib under python3 and I got :
Installing collected packages: prettyplotlib
Running setup.py install for prettyplotlib
File "/usr/lib/python3.3/site-packages/prettyplotlib/utils.py", line 125
print 'len(args) == 0'
^
SyntaxError: invalid syntax
warning: manifest_maker: MANIFEST.in, line 3: 'recursive-include' expects <dir> <pattern1> <pattern2> ...
Successfully installed prettyplotlib
Cleaning up...
Sadly this seems to be missing :(
When using prettyplotlib you have to think before every function call whether it is a plotting command implemented in prettyplotlib or some other command solely implemented in pyplot (of matplotlib). These cognitive resources could be spared if it was possible to completely switch over to prettyplotlib for all functions.
To give an example, it would be nice instead of writing
import matplotlib.pyplot as plt
import prettyplotlib as ppl
# produce data to plot
ppl.plot(x, y)
plt.xlabel('$x$')
plt.ylabel('$y$')
to be able to write
ppl.plot(x, y)
ppl.xlabel('$x$')
ppl.ylabel('$y$')
Are any other people considering this a worthwhile feature?
For implementing this I see two possibilities:
Compare
import matplotlib.pyplot as plt, prettyplotlib as ppl
f, (ax1, ax2) = plt.subplots(2)
f.subplots_adjust(hspace=0)
plt.show()
and
import matplotlib.pyplot as plt, prettyplotlib as ppl
f, (ax1, ax2) = plt.subplots(2)
f.subplots_adjust(hspace=0)
ppl.plot(ax1, [1], [1])
ppl.plot(ax2, [1], [1])
plt.show()
In the second case, by drawing white axes (I guess) around the lower plot, the upper plot's x-axis gets erased.
import prettyplotlib as ppl
with ppl.pretty:
pass
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: __exit__
Your default plot apparently plots the axes but not the tick marks, but Tufte suggests plotting the tick marks but not the axes (or at least making the axes light gray), since the tick marks are data and the axes are just a box that serves little or no information-conveying purpose.
I'm curious as to why you did the opposite of what Tufte suggests here.
by default histograms and scatterplots are have edges that are black. This is not pretty. Set edgecolor='none' by default to make this prettier
If so how please.
Thank you!
When I try using the remove_chartjunk
method for getting rid of axes plus BOTH ticklabels, that is
ppl.utils.remove_chartjunk(ax, ['top', 'right', 'left', 'bottom'], ticklabels=['x', 'y'])
only the x-axis ticklabels are suppressed. Same happens if I swap the axes, e.g. ticklabels=['y', 'x']
. Looking at the code, the issue seems to reside in a misused elif statement.
numpy
: https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt[numpydoc](https://pypi.python.org/pypi/numpydoc)
for creating sphinx-generated documentationfig1=plt.figure()
ax1=fig1.gca()
im1=ax1.imshow(tab_amp,cmap=cm.rainbow,extent=(0,90,-45,45),interpolation='bilinear')
ax1.set_xlabel(u'\u03b8 (°)')
ax1.set_ylabel(u'\u03c6 (°)')
cb1=fig1.colorbar(im1)
cb1.set_label(u'Amplitude de \u03b8ij (°)')
cs1 = ax1.contour(tab_amp_inv,colors='k',extent=(0,90,-45,45))
ax1.clabel(cs1, inline=1, fontsize=10,color='k')
I worked before then I installed prettyplotlib and now I gives this
I think prettyplotlib has changed the default font in python to a font that doesn't allow unicode character. How can I changed it back?
import prettyplotlib as ppl
import matplotlib.pyplot as plt
import numpy as np
fig, ax = ppl.subplots(1)
np.random.seed(10)
x = np.linspace(-1000,1000,10)
y = np.linspace(-1,1,80)
z = np.random.random([10,80])
X,Y = np.meshgrid(x,y)
ppl.pcolormesh(fig,ax,x,y,z.T)
plt.show()
I would have expected that ppl uses x,y,and z.T as args and then utilizes the pcolormesh(X, Y, C) instead of pcolormesh(C, **kwargs), but it seems as if this is not the case! When I look into the code of ppl.pcolormesh I do not see why this is case!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.