logo
down
shadow

Python plot drop lines with repeating value in column


Python plot drop lines with repeating value in column

By : user2172934
Date : October 22 2020, 08:10 AM
Does that help It appears that your next_1000_lines method is just doing a strip on the contents of x and y up to 1000 elements, and you are calling it on every line. Why not just to the strip as you go, once per line:
code :
line_count = 0
for line in lines:

    if line[:3] != "Max":
        tokens = line.split()
        episode = int(tokens[0].split(':')[1])
        if episode not in x:
            reward = float(tokens[7].split(':')[1])
            x.append(episode)
            y.append(reward)
            line_count += 1
    if line_count == 1000:
        linePlot = plt.plot(x, y)
        plt.show()
        linePlot[0].figure.savefig(fileName)
        line_count = 0
        x = []
        y = []


Share : facebook icon twitter icon
Plot rates with drop-down lines in R

Plot rates with drop-down lines in R


By : Sunil Chaliya
Date : March 29 2020, 07:55 AM
this will help If you want to see how rates cluster (or not) at each time slice, I think you'd do better to use points rather than vertical lines, ideally with transparent colors so you can see where they overlap. Here's one way to do that in base R, using a toy version of your data set with five y series:
code :
# Make a toy data set with five y series
set.seed(1)
df <- data.frame(time = c(paste(rep(1, 15), seq(45, 59, 1), sep=":"), paste0(rep(2, 10), ":0",  seq(0, 9)), paste(rep(2, 5), seq(10, 15), sep=":")),
    y1 = rnorm(31, 1, 0.1), y2 = rnorm(31, 1, 0.1), y3 = rnorm(31, 1, 0.1), y4 = rnorm(31, 1, 0.1), y5 = rnorm(31, 1, 0.1), stringsAsFactors=FALSE)

# Make a sequence along your time series to use as your x values; as the previous
# answer said, you can't use raw strings as x values for plotting.
df$x <- seq_along(df$time)

# Now plot them. Start by making an empty plot space that covers the full range
# of y values in your data set; then make a better x-axis; then plot the points, using
# alpha() from 'scales' to make the points transparent so overlapping ones show up.
with(df, plot(x = x, y = y1, type = "n", xaxt="n", pch=20, bg=alpha("black", 0.5), col=alpha("black", 0.5),
    ylab = "y value", xlab = "time", ylim = c(min(df[,2:6]), max(df[,2:6]))))
axis(1, at=seq(length(df$x)), labels=df$time, tick=FALSE, las=2)
for (i in 1:5) points(x = df$x, y = df[,paste0("y", i)], pch=20, col=alpha("black", 0.5))
Solve best fit polynomial and plot drop-down lines

Solve best fit polynomial and plot drop-down lines


By : Diego Zambrana
Date : March 29 2020, 07:55 AM
Hope this helps I'm using R 3.3.1 (64-bit) on Windows 10. I have an x-y dataset that I've fit with a 2nd order polynomial. I'd like to solve that best-fit polynomial for x at y=4, and plot drop-down lines from y=4 to the x-axis. , You can use the quadratic formula to calculate the values:
code :
betas <- coef(fit2)    # get coefficients
betas[1] <- betas[1] - 4    # adjust intercept to look for values where y = 4

# note degree increases, so betas[1] is c, etc.
betas
##             (Intercept) poly(x, 2, raw = TRUE)1 poly(x, 2, raw = TRUE)2 
##               8.7555833               6.0807302               0.7319848 

solns <- c((-betas[2] + sqrt(betas[2]^2 - 4 * betas[3] * betas[1])) / (2 * betas[3]), 
           (-betas[2] - sqrt(betas[2]^2 - 4 * betas[3] * betas[1])) / (2 * betas[3]))

solns
## poly(x, 2, raw = TRUE)1 poly(x, 2, raw = TRUE)1 
##               -1.853398               -6.453783 

segments(solns, -1, solns, 4, col = 'green')    # add segments to graph
polyroot(betas)
## [1] -1.853398+0i -6.453783+0i
plot dataframe column on one axis and other columns as separate lines on the same plot (in different color)

plot dataframe column on one axis and other columns as separate lines on the same plot (in different color)


By : Shmulik Almani
Date : March 29 2020, 07:55 AM
it should still fix some issue I have following dataframe. , Remove column before ploting:
code :
df.drop('cutoff', axis=1).plot()
df = df.set_index(df['cutoff'])
df.drop('cutoff', axis=1).plot()
df = df.set_index('cutoff')
df.plot()
How can I drop repeating values in a column while keeping the data for its rows?

How can I drop repeating values in a column while keeping the data for its rows?


By : user3648276
Date : March 29 2020, 07:55 AM
I hope this helps you . If want replace duplicated values to empty strings use Series.duplicated with Series.mask:
code :
df['Name'] = df['Name'].mask(df['Name'].duplicated(), '')
print (df)
  Name  Data1  Data2
0    A    0.1    1.1
1         0.2    1.2
2         0.3    1.3
3    B    0.6    1.6
4         0.7    1.7
5         0.8    1.8
6    C    1.0    2.0
7         1.1    2.1
8         1.2    2.2
df1 = df.set_index(['Name','Data1'])
print (df1)
            Data2
Name Data1       
A    0.1      1.1
     0.2      1.2
     0.3      1.3
B    0.6      1.6
     0.7      1.7
     0.8      1.8
C    1.0      2.0
     1.1      2.1
     1.2      2.2
with pd.option_context('display.multi_sparse', False):
    print (df1)

            Data2
Name Data1       
A    0.1      1.1
A    0.2      1.2
A    0.3      1.3
B    0.6      1.6
B    0.7      1.7
B    0.8      1.8
C    1.0      2.0
C    1.1      2.1
C    1.2      2.2
print (df1.index.tolist())
[('A', 0.1), ('A', 0.2), ('A', 0.3), 
 ('B', 0.6), ('B', 0.7), ('B', 0.8), 
 ('C', 1.0), ('C', 1.1), ('C', 1.2)]
Multiple lines on line plot/time series with matplotlib or plot.ly on Python

Multiple lines on line plot/time series with matplotlib or plot.ly on Python


By : Julien
Date : March 29 2020, 07:55 AM
seems to work fine Assuming your data is in a pandas dataframe df, it would be hard to plot it without the groups being in separate columns, but that is actually a step very easily done in one line,
code :
df.pivot(index="Date", columns="Group", values="Value").plot()
u = u"""Date    Group   Value
1/01/2015   A   50
2/01/2015   A   60
1/01/2015   B   100
2/01/2015   B   120
1/01/2015   C   40
2/01/2015   C   55
1/01/2015   D   36
2/01/2015   D   20"""

import io
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv(io.StringIO(u), delim_whitespace=True)
df["Date"] = pd.to_datetime(df["Date"])

df.pivot(index="Date", columns="Group", values="Value").plot()

plt.show()
Related Posts Related Posts :
  • Submitting login form with scrapy
  • How do i edit the favicon in the Browsable API in Django REST framework?
  • multiprocessing.Pool.map_async doesn't seem to... do anything at all?
  • Python Selenium: Stale Element Reference Exception Error
  • Datetime conversion - How to extract the inferred format?
  • Import YAML variables automatically?
  • How to create a powershell shortcut for my python file
  • Python's 'set' operator doesn't work with numpy.nan
  • Pass object fields and one2many fields on same method - Odoo v8
  • Select columns based on column name and location in Pandas
  • Standardizing timeseries in Pandas using interpolation
  • How many tweets can be collected?
  • how format specifier taking value while tuple list is passed
  • How to print a numpy array with data type?
  • Timeout child thread for python3
  • How can I regroup a dataframe and accumulate a colume's values?
  • Bulk Insert into SQL Server with Python not working
  • Removing last rows of each group based on condition in a pandas dataframe
  • Why the css file can not be found in Django template?
  • targeting center of mass - scipy / numpy
  • Foursquare - get tips from VENUE_ID
  • Unpack a dictionary to format
  • encoding special characters in python2
  • Replacing integers with NaN results in the entire column becoming float dtype
  • Python 3.6 - BeautifulSoup4, parse table AttributeError: ResultSet object has no attribute 'findAll'
  • Convert panda date list to python list of date strings
  • escape response from Scrapy to parse json
  • How to create a same dropdown menu for different labels?
  • Why are some python variables uppercase whereas others are lowercase?
  • Machine Learning, What are the common techniques for feature engineering and presenting the model?
  • Modify value of a Django form field during clean() and validate again
  • Heroku Django app can't start up -- 'No module named site'
  • Getting list of dates (excluding weekends)
  • Im trying to create the regular expression to include the text and not the href
  • Python file.readline(2) reads first 2 charectars
  • Groupby with handling empty bin in python
  • Modifying Gcode
  • calling a value in a dictionary within a dictionary (reading a json file)
  • Bouncing ball invalid syntax why is that?
  • Python making a counter
  • Python rstrip and split
  • What does the String mean in numpy.r_?
  • How to correctly extend variable __all__ in a __init__.py?
  • Python behaves weird with piped input
  • Python 3 two dimensional list comprehension
  • How to slice image by broadcasting slices? Error: 'only integer scalar arrays can be converted to a scalar index' in pyt
  • (Python Beginner) Need a start on classes
  • IndexError: At least one sheet must be visible
  • How to solve a system of linear equations over the nonnegative integers?
  • Pandas keep the most complete rows
  • "List index out of range" error in Python Memory Match game
  • Numpy: how to use argmax results to get the actual max?
  • Google Cloud Dataflow can't import 'google.cloud.datastore'
  • Calculate pandas DataFrame column by custom routine which accepts dictionary as input
  • Connect to a Class Method by it's method name holded into a var in a for loop in python
  • PyQt5 signals and threading.Timer
  • Replace 2 characters in a string in python
  • Passing command line arguments from a folder script to a file script
  • Understand the syntaxe X[Y == c] in Numpy
  • Optimize beginner python script about substring replacement
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org