Commit cc8311e0 by Benjamin Gallois

v1.2.0

parent 06b215db
Metadata-Version: 1.0
Name: beautifulplot
Version: 1.0.0.dev0
Version: 1.2.0
Summary: Make beautiful plot and statistical analysis effortless.
Home-page: https://github.com/bgallois/BeautifulPlot
Home-page: https://git.benjamin-gallois.fr/bgallois/BeautifulPlot
Author: Benjamin Gallois
Author-email: gallois.benjamin08@gmail.com
License: MIT
Author-email: benjamin.gallois@upmc.fr
License: GNU GENERAL PUBLIC LICENSE
Description-Content-Type: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
......@@ -33,7 +33,7 @@ class BarChart:
def plot(self, data, color = ['b', 'g', 'r', 'c' ,'m', 'y'], label = None, width = 0.35, normalized = None):
def plot(self, data, color = ['b', 'g', 'r', 'c' ,'m', 'y'], labels = None, width = 0.35, normalized = None):
"""
Description: plots a beautiful barchart
......@@ -84,8 +84,8 @@ class BarChart:
self.ax.bar(ind[i], j, self.width, color=color[i], yerr=self.std[i])
self.ax.set_xticks(ind)
if label != None:
self.ax.set_xticklabels(label)
if labels != None:
self.ax.set_xticklabels(labels)
self.ax.set_ylim([0, np.max(self.mean) + 0.5*np.max(self.mean)])
......@@ -322,6 +322,7 @@ class BarChart:
:type size: string
:param extension: format of image to save the figure.
:type size: string
:param kwargs: acces to matplotlib API.
"""
savingPath = path + '.' + extension
......
......@@ -31,7 +31,7 @@ class BoxPlot:
def plot(self, data, color = ['b', 'g', 'r', 'c' ,'m', 'y'], label = None, fancy = False, logAxis = False, positions = None, size = 0.1, **kwargs):
def plot(self, data, color = ['b', 'g', 'r', 'c' ,'m', 'y'], labels = None, fancy = False, logAxis = False, positions = None, size = 0.1, **kwargs):
"""
Description: plots a beautiful boxplot
......@@ -39,8 +39,8 @@ class BoxPlot:
:type data: list of lists/numpy arrays
:param color: color to assign at each bar, specify one element to set the same color for all bars.
:type color: list of strings
:param label: list of labels for each bar.
:type label: list of strings
:param labels: list of labels for each bar.
:type labels: list of strings
:param width: width of bars.
:type width: float
:param fancy: plot a fancy boxplot
......@@ -49,6 +49,7 @@ class BoxPlot:
:type positions: array
:param logAxis: change the x axis in log scale
:type logAxis: bool
:param kwargs: acces to matplotlib API.
"""
......@@ -58,11 +59,11 @@ class BoxPlot:
self.logAxis = True
boxWidthCompensation = lambda p, w: 10**(np.log10(p)+w/2.)-10**(np.log10(p)-w/2.)
self.width = [boxWidthCompensation(p, size) for p in positions]
bp = self.ax.boxplot(self.data, labels = label, patch_artist=True, positions = positions, widths = self.width, **kwargs)
bp = self.ax.boxplot(self.data, labels = labels, patch_artist=True, positions = positions, widths = self.width, **kwargs)
self.ax.set_xscale("log")
self.ax.set_xlim((np.min(positions) - 20*size < 0) * (np.min(positions) - 20*size), np.max(positions) + 20*size)
else:
bp = self.ax.boxplot(self.data, labels = label, patch_artist=True, **kwargs)
bp = self.ax.boxplot(self.data, labels = labels, patch_artist=True, **kwargs)
colors = plt.rcParams['axes.prop_cycle'].by_key()['color']
......@@ -343,6 +344,9 @@ class BoxPlot:
:param size: points size.
:type size: int
:param c: color of points.
:type c: str
:param kwargs: acces to matplotlib API.
"""
if self.pos == None:
......@@ -362,6 +366,7 @@ class BoxPlot:
:type size: string
:param extension: format of image to save the figure.
:type size: string
:param kwargs: acces to matplotlib API.
"""
savingPath = path + '.' + extension
......
......@@ -38,6 +38,7 @@ class ScatterPlot:
:type color: list of string
:param size: size of a point.
:type size: int
:param kwargs: acces to matplotlib API.
"""
colors = plt.rcParams['axes.prop_cycle'].by_key()['color']
......@@ -189,6 +190,7 @@ class ScatterPlot:
:type size: string
:param extension: format of image to save the figure.
:type size: string
:param kwargs: acces to matplotlib API.
"""
savingPath = path + '.' + extension
......
''' GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.'''
import matplotlib.pyplot as plt
import matplotlib.style
import matplotlib as mpl
mpl.style.use('fivethirtyeight')
import numpy as np
import scipy.stats
class ScatterPlot:
"""A simple class to make beautiful scatter plot"""
def __init__(self):
self.fig, self.ax = plt.subplots()
self.data = []
self.pointColor = []
self.pointFit = []
def plot(self, data, size = 30, color = None, marker = 'o', legend = None, **kwargs):
"""
Description: plots a beautiful scatter plot
:param data: data to plot.
:type data: list of lists/numpy arrays
:param color: color of point.
:type color: list of string
:param size: size of a point.
:type size: int
:param kwargs: acces to matplotlib API.
"""
colors = plt.rcParams['axes.prop_cycle'].by_key()['color']
colorskey = ['b', 'g', 'r', 'c' ,'m', 'y', 'k', 'w']
for k, l in enumerate(colorskey):
if color == l:
color = colors[k]
self.data = data
if color == None:
for i, j in enumerate(colorskey):
for k, l in enumerate(self.pointColor):
if j != l:
color = colors[k]
self.pointColor.append(j)
break
self.ax.scatter(data[0], data[1], c= color, s = size, marker = marker, label = legend, **kwargs)
if legend:
self.ax.legend()
def addLabels(self, xlabel = None, ylabel = None, size = 16):
"""
Description: add axis label to a beautiful barchart
:param xlabel: label for the horinzontal axis.
:type xlabel: strings
:param ylabel: label for the vertical axis.
:type ylabel: strings
:param size: size of the font.
:type size: float
"""
if xlabel:
self.ax.set_xlabel(xlabel, fontsize = size)
if ylabel:
self.ax.set_ylabel(ylabel, fontsize = size)
def addTitle(self, title = None, size = 16):
"""
Description: add title to a beautiful barchart
:param title: title the the beautiful plot.
:type title: strings
:param size: size of the font.
:type size: float
"""
if title:
self.ax.set_title(title, fontsize = size)
else:
self.ax.set_ylabel('Why call this method!?', fontsize = size)
def limits(self, xlim = None, ylim = None):
"""
Description: change axis limits to a beautiful barchart
:param xlim: limits for the horizontal axis.
:type xlim: list[xmin, xmax].
:param ylim: limits for the vertical axis.
:type ylim: list[ymin ymax].
"""
if xlim:
self.ax.set_xlim(xlim)
if ylim:
self.ax.set_ylim(ylim)
def fitting(self, data, equation = 'linear', color = None, custom = None, size = 10):
"""
Description: fit data of a beautiful scatter plot
:param equation: fitting equation. Available: 'linear', 'polynomial2', 'polynomial3', 'custom'
:type string: list[xmin, xmax].
:param custom: custom equation for fitting, def f(x, *[parameters]): return equation.
:type custom: function
"""
colors = plt.rcParams['axes.prop_cycle'].by_key()['color']
colorskey = ['b', 'g', 'r', 'c' ,'m', 'y', 'k', 'w']
for k, l in enumerate(colorskey):
if color == l:
color = colors[k]
if not color:
for i, j in enumerate(colorskey):
for k, l in enumerate(self.pointFit):
if j != l:
color = colors[k]
self.pointFit.append(j)
break
if equation == 'linear':
def f(x, a, b): return a*x+b
[popt, pcov] = scipy.optimize.curve_fit(f, data[0], data[1])
perr = np.sqrt(np.diag(pcov))
equationStr = "y = (" + str(round(popt[0],3)) + '$\pm$' + str(round(perr[0],3)) + ')x + ' + str(round(popt[1],3)) + '$\pm$' + str(round(perr[1],3))
if equation == 'polynomial2':
def f(x, a, b, c): return a*x**2+b*x+c
[popt, pcov] = scipy.optimize.curve_fit(f, data[0], data[1])
perr = np.sqrt(np.diag(pcov))
equationStr = "y = " + str(round(popt[0],3)) + '$x^{2}$ + ' + str(round(popt[1],3)) + 'x +' + str(round(popt[2],3))
if equation == 'polynomial3':
def f(x, a, b, c, d): return a*x**3+b*x**2+c*x+d
[popt, pcov] = scipy.optimize.curve_fit(f, data[0], data[1])
perr = np.sqrt(np.diag(pcov))
equationStr = 'y = ' + str(round(popt[0],3)) + '$x^{3}$ + ' + str(round(popt[1],3)) + '$x^{2}$ + ' + str(round(popt[2],3)) + 'x + ' + str(round(popt[3],3))
if custom:
[popt, pcov] = scipy.optimize.curve_fit(custom, data[0], data[1])
equationStr = ''
xMin, xMax = self.ax.get_xlim()
yMin, yMax = self.ax.get_ylim()
x = np.linspace(xMin, xMax, 10000)
self.ax.plot(x, f(x, *popt), zorder = 0, color = color)
self.ax.annotate(equationStr, xy=(xMax, yMax), xycoords='data', horizontalalignment='right', verticalalignment='top', size = size)
def save(self, path = '', extension = 'png', **kwargs):
"""
Description: save figure in a file
:param path: path where to save the figure.
:type size: string
:param extension: format of image to save the figure.
:type size: string
:param kwargs: acces to matplotlib API.
"""
savingPath = path + '.' + extension
self.fig.savefig(savingPath, **kwargs)
''' GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.'''
from .BarChart import BarChart
from .ScatterPlot import ScatterPlot
from .BoxPlot import BoxPlot
import matplotlib.pyplot as plt
def show():
plt.show()
\ No newline at end of file
......@@ -151,8 +151,20 @@
<h2 id="S">S</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="beautifulplot.html#beautifulplot.BarChart.BarChart.save">save() (beautifulplot.BarChart.BarChart method)</a>
<ul>
<li><a href="beautifulplot.html#beautifulplot.BoxPlot.BoxPlot.save">(beautifulplot.BoxPlot.BoxPlot method)</a>
</li>
<li><a href="beautifulplot.html#beautifulplot.ScatterPlot.ScatterPlot.save">(beautifulplot.ScatterPlot.ScatterPlot method)</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="beautifulplot.html#beautifulplot.ScatterPlot.ScatterPlot">ScatterPlot (class in beautifulplot.ScatterPlot)</a>
</li>
<li><a href="beautifulplot.html#beautifulplot.show">show() (in module beautifulplot)</a>
</li>
</ul></td>
</tr></table>
......
Search.setIndex({docnames:["beautifulplot","index","modules"],envversion:53,filenames:["beautifulplot.rst","index.rst","modules.rst"],objects:{"":{beautifulplot:[0,0,0,"-"]},"beautifulplot.BarChart":{BarChart:[0,1,1,""]},"beautifulplot.BarChart.BarChart":{addLabels:[0,2,1,""],addN:[0,2,1,""],addPvalueBar:[0,2,1,""],addPvalueMark:[0,2,1,""],addTitle:[0,2,1,""],limits:[0,2,1,""],plot:[0,2,1,""],plotPoints:[0,2,1,""]},"beautifulplot.BoxPlot":{BoxPlot:[0,1,1,""]},"beautifulplot.BoxPlot.BoxPlot":{addLabels:[0,2,1,""],addN:[0,2,1,""],addPvalueBar:[0,2,1,""],addPvalueMark:[0,2,1,""],addTitle:[0,2,1,""],limits:[0,2,1,""],plot:[0,2,1,""],plotPoints:[0,2,1,""]},"beautifulplot.ScatterPlot":{ScatterPlot:[0,1,1,""]},"beautifulplot.ScatterPlot.ScatterPlot":{addLabels:[0,2,1,""],addTitle:[0,2,1,""],fitting:[0,2,1,""],limits:[0,2,1,""],plot:[0,2,1,""]},beautifulplot:{BarChart:[0,0,0,"-"],BoxPlot:[0,0,0,"-"],ScatterPlot:[0,0,0,"-"]}},objnames:{"0":["py","module","Python module"],"1":["py","class","Python class"],"2":["py","method","Python method"]},objtypes:{"0":"py:module","1":"py:class","2":"py:method"},terms:{"class":0,"float":0,"function":0,"int":0,"return":0,One:0,add:0,addlabel:0,addn:0,addpvaluebar:0,addpvaluemark:0,addtitl:0,all:0,arrai:0,assign:0,avail:0,axi:0,bar:0,barchart:2,base:0,beauti:0,begin:0,bool:0,boxplot:2,cat1:0,cat2:0,chang:0,color:0,comput:0,content:2,count:0,custom:0,data:0,def:0,descript:0,displai:0,distribut:0,each:0,element:0,equat:0,fals:0,fanci:0,first:0,fit:0,font:0,horinzont:0,horizont:0,index:[0,1],insid:0,label:0,legend:0,limit:0,linear:0,list:0,make:0,mann:0,marker:0,modul:[1,2],none:0,normal:0,number:0,numpi:0,object:0,one:0,packag:2,page:1,pair:0,paramet:0,plot:0,plotpoint:0,point:0,polynomial2:0,polynomial3:0,pvalu:0,same:0,sampl:0,scatter:0,scatterplot:2,search:1,second:0,set:0,simpl:0,size:0,specifi:0,string:0,submodul:2,support:0,test:0,titl:0,top:0,ttest:0,type:0,unpair:0,used:0,valu:0,vertic:0,where:0,whitnei:0,width:0,wilcoxon:0,xlabel:0,xlim:0,xmax:0,xmin:0,ylabel:0,ylim:0,ymax:0,ymin:0},titles:["beautifulplot package","Welcome to Beautiful Plot\u2019s documentation!","beautifulplot"],titleterms:{barchart:0,beauti:1,beautifulplot:[0,2],boxplot:0,content:0,document:1,indic:1,modul:0,packag:0,plot:1,scatterplot:0,submodul:0,tabl:1,welcom:1}})
\ No newline at end of file
Search.setIndex({docnames:["beautifulplot","index","modules"],envversion:53,filenames:["beautifulplot.rst","index.rst","modules.rst"],objects:{"":{beautifulplot:[0,0,0,"-"]},"beautifulplot.BarChart":{BarChart:[0,1,1,""]},"beautifulplot.BarChart.BarChart":{addLabels:[0,2,1,""],addN:[0,2,1,""],addPvalueBar:[0,2,1,""],addPvalueMark:[0,2,1,""],addTitle:[0,2,1,""],limits:[0,2,1,""],plot:[0,2,1,""],plotPoints:[0,2,1,""],save:[0,2,1,""]},"beautifulplot.BoxPlot":{BoxPlot:[0,1,1,""]},"beautifulplot.BoxPlot.BoxPlot":{addLabels:[0,2,1,""],addN:[0,2,1,""],addPvalueBar:[0,2,1,""],addPvalueMark:[0,2,1,""],addTitle:[0,2,1,""],limits:[0,2,1,""],plot:[0,2,1,""],plotPoints:[0,2,1,""],save:[0,2,1,""]},"beautifulplot.ScatterPlot":{ScatterPlot:[0,1,1,""]},"beautifulplot.ScatterPlot.ScatterPlot":{addLabels:[0,2,1,""],addTitle:[0,2,1,""],fitting:[0,2,1,""],limits:[0,2,1,""],plot:[0,2,1,""],save:[0,2,1,""]},beautifulplot:{BarChart:[0,0,0,"-"],BoxPlot:[0,0,0,"-"],ScatterPlot:[0,0,0,"-"],show:[0,3,1,""]}},objnames:{"0":["py","module","Python module"],"1":["py","class","Python class"],"2":["py","method","Python method"],"3":["py","function","Python function"]},objtypes:{"0":"py:module","1":"py:class","2":"py:method","3":"py:function"},terms:{"class":0,"float":0,"function":0,"int":0,"public":0,"return":0,One:0,acc:0,add:0,addlabel:0,addn:0,addpvaluebar:0,addpvaluemark:0,addtitl:0,all:0,allow:0,api:0,arrai:0,assign:0,avail:0,axi:0,bar:0,barchart:2,base:0,beauti:0,begin:0,black:0,bool:0,boxplot:2,cat1:0,cat2:0,chang:0,color:0,compat:0,comput:0,content:2,coordin:0,copi:0,copyright:0,count:0,custom:0,data:0,def:0,descript:0,displai:0,distribut:0,document:0,each:0,element:0,equat:0,everyon:0,extens:0,fals:0,fanci:0,figur:0,file:0,first:0,fit:0,font:0,format:0,foundat:0,free:0,fsf:0,gener:0,gnu:0,horinzont:0,horizont:0,http:0,imag:0,inc:0,index:[0,1],insid:0,june:0,kwarg:0,label:0,legend:0,licens:0,limit:0,linear:0,list:0,log:0,logaxi:0,make:0,mann:0,marker:0,matplotlib:0,modul:[1,2],none:0,normal:0,number:0,numpi:0,object:0,one:0,order:0,org:0,packag:2,page:1,pair:0,paramet:0,path:0,permit:0,plot:0,plotpoint:0,png:0,point:0,polynomial2:0,polynomial3:0,posit:0,pvalu:0,same:0,sampl:0,save:0,scale:0,scatter:0,scatterplot:2,search:1,second:0,set:0,show:0,simpl:0,size:0,softwar:0,specifi:0,str:0,string:0,submodul:2,support:0,test:0,thi:0,titl:0,top:0,ttest:0,type:0,unpair:0,used:0,valu:0,verbatim:0,version:0,vertic:0,where:0,whitnei:0,width:0,wilcoxon:0,xlabel:0,xlim:0,xmax:0,xmin:0,ylabel:0,ylim:0,ymax:0,ymin:0},titles:["beautifulplot package","Welcome to Beautiful Plot\u2019s documentation!","beautifulplot"],titleterms:{barchart:0,beauti:1,beautifulplot:[0,2],boxplot:0,content:0,document:1,indic:1,modul:0,packag:0,plot:1,scatterplot:0,submodul:0,tabl:1,welcom:1}})
\ No newline at end of file
......@@ -6,7 +6,7 @@ import beautifulplot as bp # import beautiful plot.
import numpy as np
# generate some random data
# generate some random data
data = []
for i in range(5):
data.append(np.random.normal(np.random.randint(1, 5), np.random.randint(1,5)/10, 100))
......@@ -14,7 +14,7 @@ for i in range(5):
fig1 = bp.BarChart() # Initialize bar chart
fig1.plot(data, color = ['b', 'r', 'y', 'g', 'm'], label = ['dat1', 'dat2', 'dat3', 'dat4', 'dat5']) # Plot the bar chart
fig1.plot(data, color = ['b', 'r', 'y', 'g', 'm'], labels = ['dat1', 'dat2', 'dat3', 'dat4', 'dat5']) # Plot the bar chart
fig1.addLabels(ylabel = 'Intensity') # Add ylabel
fig1.addTitle('A beautiful Bar Chart', size = 20) # Add title
fig1.addN(size = 12) # Add number of elements in each bar
......@@ -38,7 +38,7 @@ fig2.fitting([y, x], equation = 'linear')
fig3 = bp.BoxPlot() # Initialize boxplot
fig3.plot(data, color = ['b', 'r', 'y', 'g', 'm'], label = ['dat1', 'dat2', 'dat3', 'dat4', 'dat5']) # Plot the boxplot
fig3.plot(data, color = ['b', 'r', 'y', 'g', 'm'], labels = ['dat1', 'dat2', 'dat3', 'dat4', 'dat5']) # Plot the boxplot
fig3.addLabels(ylabel = 'Intensity') # Add ylabel
fig3.addTitle('A beautiful Bar Chart', size = 20) # Add title
fig3.addN(size = 12) # Add numbver of elements in each bar
......@@ -47,4 +47,4 @@ for i in range(2, 6): # Add p-value
fig3.plotPoints(size = 2) # Plot point inside the box
bp.show()
\ No newline at end of file
bp.show()
from setuptools import setup
setup(name='beautifulplot',
version='1.1.0dev',
version='1.2.0',
description='Make beautiful plot and statistical analysis effortless.',
url='',
url='https://git.benjamin-gallois.fr/bgallois/BeautifulPlot',
author='Benjamin Gallois',
author_email='benjamin.gallois@upmc.fr',
license='GNU GENERAL PUBLIC LICENSE',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment