Beispiel #1
0
class draw_line:
    def __init__(self):

        # creates utility class object

        self.utility_obj = UtilityClass()

    def drawline(self):

        # line 1 points
        x_axes = int(input("how many values do u wanna insert in x-axis"))
        x_axes_list = self.utility_obj.CreateList(x_axes)
        print(x_axes_list)

        y_axes = int(input("how many values do u wanna insert in y-axis"))
        y_axes_list = self.utility_obj.CreateList(y_axes)
        print(y_axes_list)

        # Sets a title
        plt.title("Mat plot lib Title")

        # Set the x axis label
        plt.xlabel("x-axis")

        # Set the y axis label
        plt.ylabel("y-axis")

        # plotting the line points
        plt.plot(x_axes_list, y_axes_list)

        # Show the figure
        plt.show()
Beispiel #2
0
class plot_two_lines_with_marker:

    # creates utility class object
    utility_obj = UtilityClass()

    def draw_line(self):

        # line 1 points
        x1 = int(
            input("how many values do u wanna insert in x-axis for line1"))
        x1_list = self.utility_obj.CreateList(x1)
        print(x1_list)

        y1 = int(
            input("how many values do u wanna insert in y-axis for line1"))
        y1_list = self.utility_obj.CreateList(y1)
        print(y1_list)

        # plotting the line 1 points with marker
        plt.plot(x1_list,
                 y1_list,
                 label="line 1",
                 marker='o',
                 markerfacecolor='blue',
                 markersize=12)

        # line 2 points
        x2 = int(
            input("how many values do u wanna insert in x-axis for line2"))
        x2_list = self.utility_obj.CreateList(x2)
        print(x2_list)

        y2 = int(
            input("how many values do u wanna insert in y-axis for line2"))
        y2_list = self.utility_obj.CreateList(y2)
        print(y2_list)

        # plotting the line 2 points
        plt.plot(x2_list, y2_list, label="line 2")

        # Set the x axis label
        plt.xlabel('x - axis')
        # Set the y axis label
        plt.ylabel('y - axis')

        # Sets a title
        plt.title('Two or more lines on same plot with suitable legends ')

        # show a legend on the plot
        plt.legend()

        # Display a figure.
        plt.show()
Beispiel #3
0
class plot_quantity:
    def __init__(self):

        # creates utility class object
        self.utility_obj = UtilityClass()

    def draw_line_with_quantity(self):
        # accept size of points you wanna accept
        size = self.utility_obj.accept_size()

        # line 1 points
        x1 = self.utility_obj.CreateList(size)
        print(x1)

        y1 = self.utility_obj.CreateList(size)
        print(y1)

        # line 2 points
        x2 = self.utility_obj.CreateList(size)
        print(x2)

        y2 = self.utility_obj.CreateList(size)
        print(y2)

        # Set the x axis label
        plt.xlabel('x - axis')
        # Set the y axis label
        plt.ylabel('y - axis')

        # Sets a title
        plt.title(' quantities which have an x and y position ')

        # set new axes limits
        plt.axis([0, 100, 0, 100])

        # use pylab to plot x and y as red circles
        plt.plot(x1, y1, 'b*', x2, y2, 'ro')

        # shows the plot
        plt.show()
Beispiel #4
0
class subplot:
    # creates utility class object
    utility_obj = UtilityClass()

    def create_subplot(self):

        # accept size of points you wanna accept
        size = self.utility_obj.accept_size()

        # line 1 points
        print("enter line 1 x axis values")
        x1 = self.utility_obj.CreateList(size)
        print(x1)
        print("enter line 1 y axis values")
        y1 = self.utility_obj.CreateList(size)
        print(y1)

        # Sets up a subplot grid that has height 2 and width 1,
        # and set the first such subplot as active.
        plt.subplot(2, 1, 1)

        # plotting the line 1 points
        plt.plot(x1, y1, label="line 1")

        # Sets a title
        plt.title('subplot1')

        print("line 2")
        # accept size of points you wanna accept for line 2
        size_l2 = self.utility_obj.accept_size()

        # line 2 points
        print("enter line 2 x axis values")
        x2 = self.utility_obj.CreateList(size_l2)
        print(x2)
        print("enter line 2 y axis values")
        y2 = self.utility_obj.CreateList(size_l2)
        print(y2)

        # Set the second subplot as active, and make the second plot.
        plt.subplot(2, 1, 2)

        # plotting the line 2 points
        plt.plot(x2, y2, label="line 2")

        # Sets a title
        plt.title('subplot2')

        # Shows the figure.
        plt.show()
Beispiel #5
0
class Set_Get_Axis_Values:

    # line 1 points
    utility_obj = UtilityClass()

    def draw_line(self):

        # line 1 points
        x1 = int(
            input("how many values do u wanna insert in x-axis for line1"))
        x1_list = self.utility_obj.CreateList(x1)
        print(x1_list)

        y1 = int(
            input("how many values do u wanna insert in y-axis for line1"))
        y1_list = self.utility_obj.CreateList(y1)
        print(y1_list)

        # plotting the line 1 points
        plt.plot(x1_list, y1_list, label="line 1")

        # Set the x axis label
        plt.xlabel('x - axis')
        # Set the y axis label
        plt.ylabel('y - axis')

        # Sets a title
        plt.title('Two or more lines on same plot with suitable legends ')

        # returns current axis values
        print(plt.axis())

        # accepting values to set new axis values
        print("set new axis limit")

        x_min = int(input("x_min val"))
        x_max = int(input("x_max val"))
        y_min = int(input("y_min val"))
        y_max = int(input("y_max val"))

        # sets new axis values
        plt.axis([x_min, x_max, y_min, y_max])

        # show a legend on the plot
        plt.legend()

        # Display a figure.
        plt.show()
Beispiel #6
0
    def __init__(self):

        # creates utility class object

        self.utility_obj = UtilityClass()
Beispiel #7
0
class plot_two_lines:

    # creates utility class object
    utility_obj = UtilityClass()

    def draw_line(self):

        # line 1 points
        x1 = int(
            input("how many values do u wanna insert in x-axis for line1"))
        x1_list = self.utility_obj.CreateList(x1)

        print(x1_list)

        y1 = int(
            input("how many values do u wanna insert in y-axis for line1"))
        y1_list = self.utility_obj.CreateList(y1)
        print(y1_list)

        # line 2 points
        x2 = int(
            input("how many values do u wanna insert in x-axis for line2"))
        x2_list = self.utility_obj.CreateList(x2)

        print(x2_list)

        y2 = int(
            input("how many values do u wanna insert in y-axis for line2"))
        y2_list = self.utility_obj.CreateList(y2)
        print(y2_list)

        # Set the x axis label
        plt.xlabel('x - axis')

        # Set the y axis label
        plt.ylabel('y - axis')

        # Sets a title
        plt.title(
            'Two or more lines on same plot with legends, different widths and colors '
        )

        # plotting the line 1 points with color,width,label
        plt.plot(x1_list,
                 y1_list,
                 color='blue',
                 linewidth=2,
                 label="line1-width-2")

        # plotting the line 2 points with color,width,label
        plt.plot(x2_list,
                 y2_list,
                 color='black',
                 linewidth=4,
                 label="line2-width-4")

        # show a legend on the plot
        plt.legend()

        # Display a figure.
        plt.show()
Beispiel #8
0
class plot_two_lines_with_style:
    # creates utility class object
    utility_obj = UtilityClass()

    def draw_line(self):

        # line 1 points
        x1 = int(
            input("how many values do u wanna insert in x-axis for line1"))
        x1_list = self.utility_obj.CreateList(x1)
        print(x1_list)

        y1 = int(
            input("how many values do u wanna insert in y-axis for line1"))
        y1_list = self.utility_obj.CreateList(y1)
        print(y1_list)

        # plotting the line 1 points with dash line style
        plt.plot(x1_list, y1_list, linestyle='dashed', label="line 1")

        # line 2 points
        x2 = int(
            input("how many values do u wanna insert in x-axis for line2"))
        x2_list = self.utility_obj.CreateList(x2)
        print(x2_list)

        y2 = int(
            input("how many values do u wanna insert in y-axis for line2"))
        y2_list = self.utility_obj.CreateList(y2)
        print(y2_list)

        # plotting the line 2 points with Dotted line style
        plt.plot(x2_list, y2_list, linestyle=':', label="line 2")

        # line 3 points
        x3 = int(
            input("how many values do u wanna insert in x-axis for line2"))
        x3_list = self.utility_obj.CreateList(x3)
        print(x3_list)

        y3 = int(
            input("how many values do u wanna insert in y-axis for line2"))
        y3_list = self.utility_obj.CreateList(y3)
        print(y3_list)

        # plotting the line 3 points with Dash-dot line style
        plt.plot(x3_list, y3_list, linestyle='-.', label="line 2")

        # Set the x axis label
        plt.xlabel('x - axis')
        # Set the y axis label
        plt.ylabel('y - axis')

        # Sets a title
        plt.title('Two or more lines on same plot with suitable legends ')

        # show a legend on the plot
        plt.legend()

        # Display a figure.
        plt.show()
Beispiel #9
0
class bar_chart_vertically:
    # creates utility class object
    utility_obj = UtilityClass()

    # accept size of points you wanna accept
    size = utility_obj.accept_size()

    # accepts x axis values
    print("enter programming languages")
    language = utility_obj.accept_languages(size)
    print(language)

    # accepts y axis values
    print("enter popularity")
    popularity = utility_obj.accept_popularity(size)
    print(popularity)

    # Set the x axis label
    plt.xlabel("Languages")

    # Set the y axis label
    plt.ylabel("Popularity")

    # Sets a title
    plt.title("Popularity of Programming Languages")

    def draw_bar_vertically(self):

        # iterate through no.of language
        x_pos = [i for i, _ in enumerate(self.language)]

        # plotting x and y axis values to create bar chart
        plt.bar(x_pos, self.popularity, color='blue')

        # set the current tick locations and labels(language name)of the x-axis
        plt.xticks(x_pos, self.language)

        # Shows the figure.
        plt.show()

    def draw_bar_horizontally(self):
        # iterate through no.of language
        x_pos = [i for i, _ in enumerate(self.language)]

        # plotting x and y axis values to create bar chart horizontally
        plt.barh(x_pos, self.popularity, color='green')

        # set the current tick locations and labels(language name) to y-axis
        plt.yticks(x_pos, self.language)

        plt.show()

    def draw_bar_with_uniform_color(self):
        # iterate through no.of language
        x_pos = [i for i, _ in enumerate(self.language)]

        # plotting x and y axis values to create bar chart
        plt.bar(x_pos, self.popularity, color=(0.2, 0.4, 0.6, 0.6))

        # set the current tick locations and labels(language name)of the x-axis
        plt.xticks(x_pos, self.language)

        # Shows the figure.
        plt.show()

    def draw_bar_with_diff_color(self):
        # iterate through no.of language
        x_pos = [i for i, _ in enumerate(self.language)]

        # plotting x and y axis values to create bar chart
        plt.bar(x_pos,
                self.popularity,
                color=['black', 'red', 'green', 'blue', 'cyan'])

        # set the current tick locations and labels(language name)of the x-axis
        plt.xticks(x_pos, self.language)

        # Shows the figure.
        plt.show()

    def attach_label(self):

        # iterate through no.of language
        x_pos = [i for i, _ in enumerate(self.language)]

        # plotting x and y axis values to create bar chart
        # plt.bar(x_pos, self.popularity, color='blue')

        # set the current tick locations and labels(language name)of the x-axis
        # plt.xticks(x_pos, self.language)

        fig, ax = plt.subplots()
        rects1 = ax.bar(x_pos, self.popularity, color='b')
        plt.xticks(x_pos, self.language)

        # for i, v in enumerate(rects1):
        #     ax.text(v + 3, i + .25, str(v), color='red', fontweight='bold')

        def autolabel(rects):
            # Attach a text label above each bar displaying its height
            for rect in rects:
                height = rect.get_height()
                print("getx", rect.get_x())
                ax.text(rect.get_x() + rect.get_width() / 2.,
                        1.05 * height,
                        '%f' % float(height),
                        ha='center',
                        va='bottom')

        autolabel(rects1)

        # Shows the figure.
        plt.show()

    def make_border(self):
        # iterate through no.of language
        x_pos = [i for i, _ in enumerate(self.language)]

        # plotting x_pos and popularity values to create bar chart
        plt.bar(x_pos, self.popularity, color='red', edgecolor='blue')

        # set the current tick locations and labels(language name)of the x-axis
        plt.xticks(x_pos, self.language)

        # Shows the figure.
        plt.show()

    def increase_margin(self):
        # iterate through no.of language
        x_pos = [i for i, _ in enumerate(self.language)]
        # plotting x_pos and popularity values to create bar chart
        plt.bar(x_pos, self.popularity, color=(0.4, 0.6, 0.8, 1.0))

        # Rotation of the bars names
        plt.xticks(x_pos, self.language)

        # Custom the subplot layout
        plt.subplots_adjust(bottom=0.10, top=.4)

        # Shows the figure.
        plt.show()

    def specify_width_position(self):

        x_pos = [i for i, _ in enumerate(self.language)]

        plt.xticks(x_pos, self.language)

        # Select the width of each bar and their positions
        width = [0.1, 0.2, 0.5, 1.1, 0.2, 0.3]
        y_pos = [0, .8, 1.5, 3, 5, 6]

        # Create bars
        plt.bar(y_pos, self.popularity, width=width)
        plt.xticks(y_pos, self.language)

        plt.show()

    def menu(self):

        print("1.print output vertically")
        print("2.print output horizontally")
        print("3.bar with Uniform color")
        print("4.bar with different color")
        print("5.Attach a text label above each bar displaying its popularity")
        print("6.Make blue border to each bar")
        print("9.Increase bottom margin")
        print("0.exit")
        flag = False

        while not flag:
            try:
                choice = int(input("\nEnter ur choice"))
                if choice >= 0 and choice <= 15:

                    if choice == 1:
                        obj.draw_bar_vertically()

                    if choice == 2:
                        obj.draw_bar_horizontally()

                    if choice == 3:
                        obj.draw_bar_with_uniform_color()

                    if choice == 4:
                        obj.draw_bar_with_diff_color()

                    if choice == 5:
                        obj.attach_label()
                    if choice == 6:
                        obj.make_border()

                    if choice == 7:
                        obj.specify_width_position()

                    if choice == 9:
                        obj.increase_margin()

                    if choice == 0:
                        flag = True
                else:
                    raise ValueError
            except ValueError:
                print("\nPlease give valid input and Try again")