Help Needed (in .text function):
Right now text function just adds height of text (a constant a calculated manually) based on fontsize for next line sub-text.
It doesn't work as expected many times. So, I want to change it in a matplolib way to calculate new line y value.
Using Pip:
pip install SWMat
Download from pypi: SWMat.tar.gz
from SWMat.SWMat import SWMat # Will change it soon...
You can initialize SWMat
class in two ways:
- Either you can only pass
matplotlib.pyplot
directly,
import matplotlib.pyplot as plt
swm = SWMat(plt) # Will take current Axes
- Or you can pass
Axes
withmatplotlib.pyplot
to beautify givenAxes
.
import matplotlib.pyplot as plt
fig, axs = plt.subplots(3, 4)
swm = SWMat(plt, ax=axs[0][1])
There are 'two' main differentiating features of this package:
- Base beautifications are done without much hassle,
swm = SWMat(plt) # And... The Base beautifications will be added.
plt.scatter(x, y)
- You can easily plot text on your plot using
SWMat.text
,
swm = SWMat(plt) # This function will initialize your plot
plt.scatter(x, y)
swm.text(some_text); # That's all!! Don't worry there's much more you can do with it.
- And there is a
highlight
parameter available with every function inSWMat
, to help you highlight some part of plot for that particular plot type.
Main parameters to look for here are: line_labels
(Label for each line plot) and highlight
(int or list of lines to highlight).
swm = SWMat(plt)
swm.line_plot(xs, ys, line_labels=["A", "B"], highlight=0, lw=3);
Main parameters to look for here are: highlight
(int orlist of index of bins to highlight).
swm = SWMat(plt)
swm.hist(data, highlight=3, bins=bins);
swm = SWMat(plt)
swm.hist(data, highlight=3, bins=bins, hide_y=True);
Main parameters to look for here are: plot_type
(horizontal, vertical etc), cat_labels
(labels for categories in each data vector), data_labels
(labels for each data vector) and highlight
(dictionary taking int or list of ints for highlighting particular data bars or given category bars).
swm = SWMat(plt)
swm.bar(cats, heights, data_labels=["A", "B", "C", "D"], cat_labels=["One", "Two", "Three"], highlight={"data":1});
swm = SWMat(plt)
swm.bar(cats, heights, data_labels=["Alpha", "Beta"], highlight={"data":1, "cat":1},
cat_labels=["One", "Two", "Three"], plot_type="stacked100%");
Main parameters to look for here are: show
(where violin\dist plot(s) should be shown), highlight
(dictionary taking list of tuples of starting and ending points inbetween which to highlight, with keys as index of violin plot. Actually you can plot many violin plots simultaneously.)
swm = SWMat(plt)
swm.violinplot(data, show="top", highlight={"0":[(0.7, 2.3), (4.7, 6)]})
Main feature of text function of SWMat is that you can type in paragraphs of text without using matplotlib's plot function again and again, and that too while using HTML like attribute specification using prop
tag. So you can configure your text as:
text = "Lorem <prop fontsize='20', color='#FF7700'>ipsum dolor</prop> sit amet." # All attribute's values needs to be inside quotes (As "value" or 'value').
prop
tag can take all attributes of fontdict
available in matplotlib.
- Knaflic, Cole. Storytelling With Data: A Data Visualization Guide for Business Professionals, Wiley, © 2015
- Matplotlib Library Docs