Example #1
0
def graph_authors(ratings, no_subplot, d3_plot, to_file, no_date=True):
    """
    This function prints graphs with library matplotlib and mpld3.
    Take arguments:
        ratings = nested dictionary which contains like key author, like data
                other metrics like pylint output, radon output, algorithms
                from QMetric and another for graphs
        no_subplot = if enable will be plots every curves in one graph else
                        plots every statistic to diffrent graph
        d3_plot = if enable is used for plotting library matplotlib + mpld3
                    else there will be graphs only in matplotlib
        no_dates = if enable which is in default, the x axis will have only
                    index of commit
    """
    for author in ratings:
        geted = get_lists_for_graphs(ratings, author)
        list_comm = geted[0]
        list_pylint = geted[1]
        list_metrics = geted[2]
        list_rating_two = geted[3]
        list_dates = geted[4]
        if len(list_pylint) < 2:
            continue
        fig, ax = plt.subplots()
        authorl = author.replace(" ", "_")
        authorl = authorl.replace(".", "")
        plt.title("Author: {0}".format(authorl))
        ax.bar(range(4), [ratings[author]["hyphotetical_rating_one"],
                ratings[author]["hyphotetical_rating_two"],
                ratings[author]["pylint_rating"],
                ratings[author]["radon_rating"]], align="center")
        plt.xticks(range(4), ["First algorithm", "Second algorithm",
                           "Average pylint", "Average Radon"], size="small")
        plt.savefig(r"final_results_{0}".format(authorl))
        fig, ax = plt.subplots()
        if no_date:
            list_dates = [num for num in xrange(len(list_comm))]
        plt.ylabel("Ratings %")
        plt.xlabel("Number of commits")
        if no_subplot:
            plt.ylim([-1, 101])
            plt.plot(list_dates, list_comm, color="red")
            plt.plot(list_dates, list_rating_two, color="black")
            plt.plot(list_dates, list_pylint, color="blue")
            plt.plot(list_dates, list_metrics, color="green")
        else:
            plt.ylim([0, 101])
            plt.subplot(411)
            plt.ylabel("Ratings %")
            plt.xlabel("Number of commits")
            plt.plot(list_dates, list_comm, color="red")
            plt.title("Author: {0}".format(authorl))
            plt.subplot(412)
            plt.ylabel("Ratings %")
            plt.xlabel("Number of commits")
            plt.plot(list_dates, list_rating_two, color="black")
            plt.subplot(413)
            plt.ylabel("Ratings %")
            plt.xlabel("Number of commits")
            plt.plot(list_dates, list_pylint, color="blue")
            plt.subplot(414)
            plt.ylabel("Ratings %")
            plt.xlabel("Number of commits")
            plt.plot(list_dates, list_metrics, color="green")
        fig.autofmt_xdate()
        if to_file:
            plt.savefig(r"graph_rep_{0}".format(authorl))
        else:
            plt.show()
        if d3_plot and to_file:
            get_d3()
            plugins.connect(fig, plugins.Reset(), plugins.Zoom())
            show_d3()
Example #2
0
"""
Scatter Plot With Tooltips
==========================
A scatter-plot with tooltip labels on hover
"""
import matplotlib.pyplot as plt
import numpy as np
from mpld3 import plugins, show_d3

fig, ax = plt.subplots(subplot_kw=dict(axisbg='#EEEEEE'))
N = 100

scatter = ax.scatter(np.random.normal(size=N),
                     np.random.normal(size=N),
                     c=np.random.random(size=N),
                     s = 1000 * np.random.random(size=N),
                     alpha=0.3,
                     cmap=plt.cm.jet)
ax.grid(color='white', linestyle='solid')

ax.set_title("Scatter Plot (with tooltips!)", size=20)

labels = ['point {0}'.format(i + 1) for i in range(N)]
tooltip = plugins.PointLabelTooltip(scatter, labels=labels)
plugins.connect(fig, tooltip)

show_d3()

Example #3
0
s = 100 + 500 * np.random.random(100)

ax[0, 1].scatter(x, y, c=c, s=s, alpha=0.3)
ax[0, 1].set_title('A Scatter Plot')

#----------------------------------------------------------------------
# third plot: some random lines
x = np.linspace(0, 10, 100)
y = np.sin(x)
dy = 0.4

ax[1, 0].plot(x, y, '--k', lw=2)

for i in range(20):
    y_plot = np.convolve(np.ones(5) / 5., np.random.normal(y, dy), mode='same')
    ax[1, 0].plot(x, y_plot, '-b', lw=2, alpha=0.1)

ax[1, 0].set_title('Transparent Lines')

#----------------------------------------------------------------------
# fourth plot: filled regions
x = np.linspace(0, 4 * np.pi, 100)
y1 = np.sin(x / 2)
y2 = np.sin(x)

ax[1, 1].fill_between(x, y1, y2, where=y1 > y2, color='blue', alpha=0.3)
ax[1, 1].fill_between(x, y1, y2, where=y1 <= y2, color='red', alpha=0.3)
ax[1, 1].set_title('fill_between()')

show_d3()