logo
down
shadow

Average line for bar chart in matplotlib


Average line for bar chart in matplotlib

By : user2954258
Date : November 22 2020, 01:01 AM
this one helps. If you'd like a vertical line to denote the mean use axvline(x_value). This will place a vertical line that always spans the full (or specified fraction of) y-axis. There's also axhline for horizontal lines.
In other works, you might have something like this:
code :
ax.axvline(data1.mean(), color='blue', linewidth=2)
ax.axvline(data2.mean(), color='green', linewidth=2)
import numpy as np
import matplotlib.pyplot as plt

data1 = np.random.normal(0, 1, 1000)
data2 = np.random.normal(-2, 1.5, 1000)

fig, ax = plt.subplots()

bins = np.linspace(-10, 5, 50)
ax.hist(data1, bins=bins, color='blue', label='Dataset 1',
        alpha=0.5, histtype='stepfilled')
ax.hist(data2, bins=bins, color='green', label='Dataset 2',
        alpha=0.5, histtype='stepfilled')

ax.axvline(data1.mean(), color='blue', linewidth=2)
ax.axvline(data2.mean(), color='green', linewidth=2)

# Add arrows annotating the means:
for dat, xoff in zip([data1, data2], [15, -15]):
    x0 = dat.mean()
    align = 'left' if xoff > 0 else 'right'
    ax.annotate('Mean: {:0.2f}'.format(x0), xy=(x0, 1), xytext=(xoff, 15),
            xycoords=('data', 'axes fraction'), textcoords='offset points',
            horizontalalignment=align, verticalalignment='center',
            arrowprops=dict(arrowstyle='-|>', fc='black', shrinkA=0, shrinkB=0,
                            connectionstyle='angle,angleA=0,angleB=90,rad=10'),
            )

ax.legend(loc='upper left')
ax.margins(0.05)
plt.show()


Share : facebook icon twitter icon
SSRS Line Chart: Adding an Average/Target line to Line Chart

SSRS Line Chart: Adding an Average/Target line to Line Chart


By : Jim
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Can change all of that information/treatment by modifying the series.
Firstly change the Chart Type of the series to Area
Combined bar and line chart JfreeChart. Trying to make a 3 point average with the line chart. The values do not line up

Combined bar and line chart JfreeChart. Trying to make a 3 point average with the line chart. The values do not line up


By : user3719931
Date : March 29 2020, 07:55 AM
wish of those help I ended up using a try and catch block, but an if and else also would have worked. Where you dont want any values just put null as the value.
code :
    for(int i=0;i<ints1.size();i++)
    {
        dataset.addValue(ints1.get(i), "Good Product", "Hour" + String.valueOf(i+1));
        dataset.addValue(ints2.get(i), "Bad Product", "Hour" + String.valueOf(i+1));
        try{
            dataset2.addValue((ints1.get(i) + ints1.get(i-1) + ints1.get(i-2))/3, "Time", "Hour" + String.valueOf(i+1));
            }
            catch(ArrayIndexOutOfBoundsException e)
            {
                dataset2.addValue(null, "Time", "Hour" + String.valueOf(i+1));
            }
    }
matplotlib:line chart to show all products price on each date with matplotlib or seaborn

matplotlib:line chart to show all products price on each date with matplotlib or seaborn


By : Michael Roostig
Date : March 29 2020, 07:55 AM
Hope this helps how to use line chart to show all products price on each date in one chart? , Assuming your dataframe:
code :
import pandas as pd

df = pd.DataFrame({'product':['pen','apple','book','cup','pen','apple','book','cup','pen','apple','book','cup',],
                   'price':[1,2,3,4,0.8,2.2,3.1,3.5,.6,2.6,2.1,4.3],
                   'date':['20190101','20190101','20190101','20190101','20190102','20190102','20190102','20190102','20190103','20190103','20190103','20190103']})
import matplotlib.pyplot as plt

for i in df.groupby('product'):
    plt.plot(i[1].date,i[1].price,'-o',label=i[0])

plt.legend(loc='upper center',
           bbox_to_anchor=(0.5, -0.2),
           fancybox=True,
           shadow=True,
           ncol=4)
plt.xlabel('date')
plt.ylabel('price')
plt.show()
Add label values to bar chart and line chart in matplotlib

Add label values to bar chart and line chart in matplotlib


By : user3458057
Date : March 29 2020, 07:55 AM
like below fixes the issue Here is a modified function that will achieve the required task. The trick is to extract the x and y values based on the type of the chart you have. For a line chart, you can use ax.lines[0] and then get_xdata and get_ydata
code :
def add_value_labels(ax, typ, spacing=5):
    space = spacing
    va = 'bottom'

    if typ == 'bar':
        for i in ax.patches:
            y_value = i.get_height()
            x_value = i.get_x() + i.get_width() / 2

            label = "{:.0f}".format(y_value)
            ax.annotate(label,(x_value, y_value), xytext=(0, space), 
                    textcoords="offset points", ha='center', va=va)     
    if typ == 'line':
        line = ax.lines[0]
        for x_value, y_value in zip(line.get_xdata(), line.get_ydata()):
            label = "{:.2f}".format(y_value)
            ax.annotate(label,(x_value, y_value), xytext=(0, space), 
                textcoords="offset points", ha='center', va=va)   

add_value_labels(ax, typ='bar')
add_value_labels(ax2, typ='line')
Matplotlib - overlaying line chart on bar chart and aligning yticks

Matplotlib - overlaying line chart on bar chart and aligning yticks


By : user3567094
Date : March 29 2020, 07:55 AM
help you fix your problem You can plot both in ax1, and remove the y_pos, because at the end both of them share the group variable as y coordinate.
Then, you can add a height to the barh plot.
code :
import matplotlib.pyplot as plt

group = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]
amount1 = [967, 975, 1149, 1022, 852, 975, 1025, 1134, 994, 1057, 647, 1058]
amount2 = [286, 364, 111, 372, 333, 456, 258, 152, 400, 181, 221, 441]

f, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, sharey=True, figsize=(17, 8))

# plot men
a = ax1.barh(group, amount1, height=4)
ax1.plot(amount2, group, color='black', marker='o')

# ticks
ax1.set_yticks(group)
ax1.set_yticklabels(group)
ax1.invert_xaxis()
ax1.yaxis.tick_right()

# padding
plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0.05,
                    hspace=None)

plt.show()
plt.close() 
Related Posts Related Posts :
  • Remove commas in a string, surrounded by a comma and double quotes / Python
  • How to chain Django querysets preserving individual order
  • Comparison with Python
  • How to find backlinks in a website with python
  • Return new instance of subclass when using methods inherited from parent class in Python
  • Which function in django.contrib.auth creates the default model permissions?
  • Formatting text in tabular form with Python
  • How to determine the first day of a month in Python
  • Error while converting date to timestamp in python
  • Python string iterations
  • Is there any file number limitation when you select multiple files with wxFileDialog?
  • Errors with Matplotlib when making an executable with Py2exe (Python)
  • Django Haystack - Indexing single field
  • Go Pro Hero 3 - Streaming video over wifi
  • Appending a column in .csv with Python/Pandas
  • How to change my result directory in Robot framework using RIDE?
  • problem with using pandas to manipulate a big text file in python
  • python-magic module' object has no attribute 'open'
  • Where goes wrong for this High Pass Filter in Python?
  • Why inserting keys in order into a python dict is faster than doint it unordered
  • flann index saving in python
  • Create new instance of list or dictionary without class
  • How can I easily convert FORTRAN code to Python code (real code, not wrappers)
  • Address of lambda function in python
  • Python adding space between characters in string. Most efficient way
  • python http server, multiple simultaneous requests
  • Disguising username & password on distributed python scripts
  • Post GraphQL mutation with Python Requests
  • Why doesnt pandas create an excel file?
  • Rolling comparison between a value and a past window, with percentile/quantile
  • How to avoid repetitive code when defining a new type in python with signature verification
  • How to configure uWSGI in order to debug with pdb (--honour-stdin configuration issue)
  • In Python, how do you execute objects that are functions from a list?
  • Python- Variable Won't Subtract?
  • Processing Power In Python
  • Python 2.7.2 - Cannot import name _random or random from sys
  • Why doesn't the Python sorted function take keyword order instead of reverse?
  • Make a function redirect to other functions depending on a variable
  • get_absolute_url in django-categories
  • Monitoring non-Celery background task with New Relic in Python
  • Feature selection with LinearSVC
  • LSTM - Predicting the same constant values after a while
  • Test the length of elements in a list
  • Django: render radiobutton with 3 columns, cost column must change according to size & quantity selected
  • Python class attributes vs global variable
  • sys.stdout.writelines("hello") and sys.stdout.write("hello")
  • is ndarray faster than recarray access?
  • Python - search through directory trees, rename certain files
  • GAE: How to build a query where a string begins with a value
  • TypeError: __init__() takes at least 2 arguments (1 given)
  • Overriding and customizing "django.contrib.auth.views.login"
  • Django : Redirect to a particular page after login
  • Python search and copy files in directory
  • pretty printing numpy ndarrays using unicode characters
  • Frequent pattern mining in Python
  • How can I make a set of functions that can be used synchronously as well as asynchronously?
  • Convert one dice roll to two dice roll
  • count occourrence in a list
  • Writing an If condition to filter out the first word
  • to read file and compare column in python
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org