Tags down


how to make scatter plot of two columns and divide x_axis in 3 column f1,f2,and f3

By : jacob
Date : October 17 2020, 06:10 AM
This might help you I have dataframe i want to draw a scattor plot by dividing plot in 2 regions in region one only plot f_x_f1 vs A_x_f1, and in region2 plot f_x_f2 vs A_x_f2 , Here, using matplotlib!
code :
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

### making some sample data
df = pd.DataFrame({"f_x_f1": np.random.randint(1,100,100) 
                    , "A_x_f1": np.random.randint(1,100,100)    
                    , "f_x_f2": np.random.randint(1,100,100) 
                    , "A_x_f2": np.random.randint(1,100,100) })

fig, ax = plt.subplots(nrows=1, ncols=2)
ax[0].set_title("f_x_f1 vs A_x_f1")

ax[1].set_title("f_x_f2 vs A_x_f2")

Share : facebook icon twitter icon

Is there a way to make matplotlib scatter plot marker or color according to a discrete variable in a different column?

By : Sami
Date : March 29 2020, 07:55 AM
Hope this helps What you're doing will almost work, but you have to pass color a vector of colors, not just a vector of variables. So you could do:
code :
color = df.Group.map({dut_groups[0]: "r", dut_groups[1]: "b"})
plt.scatter(x, y, color=color)
import seaborn as sns
import pandas as pd
from numpy.random import randn

data = pd.DataFrame(dict(x=randn(40), y=randn(40), g=["a", "b"] * 20))
sns.lmplot("x", "y", hue="g", data=data, fit_reg=False)

How to plot a scatter plot using a pandas dataframe where the x-axis values are n minus 1 columns and the last column is

By : F Yudhi Lesmana
Date : March 29 2020, 07:55 AM
Does that help First, you should move the declaration of fig, axes outside the loop so you don't create a new figure for each column.
Also, looping over for i,j in row, column: does not work and would create another loop within your loop over the columns, which you don't want.
code :
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# make sample dataframe
dicts = {}
keys = range(12)
for i in keys:
        dicts["x%s"%i] = list(np.random.randint(40, size=20))
dicts["y12"] = list(range(1,21))
df_sample = pd.DataFrame(dicts)

# function to plot your dataframe
def plot_df_scatter_columns(df):
    fig, axes = plt.subplots(3,4, figsize = (12, 8))

    # initialize i and j

    # loop over df.iloc[:, :-1] instead of df
    # to leave out last column in loop
    for z in df.iloc[:, :-1]:
        axes[i, j].scatter(df[z], df['y12'])
        axes[i, j].set_title(z + 'vs. y12')
        # calculate i and j on the fly during loop over df
        j += 1
        if j > 3:
            i += 1



How to make a scatter plot with non-numerical column?

By : user3087868
Date : March 29 2020, 07:55 AM
With these it helps y_range parameter fixed the issue for me.
I found it at Handling Categorical Data.
code :
p = figure(
    y_range=df['b'], # < -- what I added 
    title="Something great",

How to make a scatter plot with varying scatter size and color corresponding to a range of values from a dataframe?

By : user3367289
Date : March 29 2020, 07:55 AM
hope this fix your issue You could use pandas.cut to create a couple of helper columns in df based on your color and size mappings. This should make it easier to pass these arguments to pyplot.scatter.
N.B. It's worth noting that the values you've chosen for size may not distinguish the markers very well in the plot - it'd be worth experimenting with different sizes until you get the desired results
code :
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

df['color'] = pd.cut(df['Depth'], bins=[-np.inf, 30, 40, 60, np.inf], labels=['red', 'blue', 'black', 'yellow'])
df['size'] = pd.cut(df['Magnitude'], bins=[-np.inf, 2, 3, 4, np.inf], labels=[1, 1.5, 2, 2.5])

plt.scatter(df['Lon'], df['Lat'], c=df['color'], s=df['size'])
def magnitude_size(magnitude):
    if magnitude < 2 :
        return 1
    if magnitude >= 2 and magnitude < 3 :
        return 1.5
    if magnitude >= 3 and magnitude < 4 :
        return 2
    if magnitude >= 4  :
        return 2.5

def depth_color(depth):
    if depth < 30 :
        return 'red'
    if depth >= 30 and depth < 40 :
        return 'blue'
    if depth >= 40 and depth < 60 :
        return 'black'
    if depth >= 60  :
        return 'yellow'
    if np.isnan(depth):
        return 'green'

di = {
    'size': df.Magnitude.apply(magnitude_size),
    'color' : df.Depth.apply(depth_color)


Excel - How can I make a scatter plot which colors by a third column?

By : Madhur Chauhan
Date : March 29 2020, 07:55 AM
this will help This is the best (non-vba) way I can think of to go about this (I'd recommend VBA if you know the language), but it may involve too much manual work depending on how many types you really have.
To start, flip the Y and X columns, and add a new column for each datatype you have (see image below)
Related Posts Related Posts :
  • Why is the interpreter call the variable i a local variable
  • Passing multiple list in a function as *args gives a None result
  • Getting a tclerror with PhotoIMage
  • How to efficiently disaggregate data from?
  • Group by the dates to weeks
  • Accuracy problems in estimating pi using Machin's method
  • Printing a list method return None
  • Can I install python 3.7 in ubuntu 18.04 without having python 3.6 in the system?
  • Applying a function to every cell of dataframes
  • Cant install allennlp with pip on mac
  • ModuleNotFoundError: No module named 'virtualenv' Exiting due to failure, even after virtual environment is successfully
  • How to fix " 'int' object is not subscriptable" on this code
  • question about custom sorting using key argument in sorted()
  • Python3-tk is already installed but python3.7 can't find module tkinter
  • Pickle messing up text
  • How to install torch==0.3.1 in python=3.6
  • Tkinter Checkbuttons' values won't change
  • How to call asynchronous functions without expecting returns from them?
  • Unable to convert string to date (Portuguese locale)
  • Use textract on PDF file located on Google Cloud Storage
  • How to fix 'Can't open libmsodbcsql-17.3.so.1.1'
  • Using the join method in python - confusing error
  • Pandas Dataframe to .csv file
  • Tell if an object's attribute has been used
  • Read files from Cloud Storage having definite prefix but random postfix
  • Extract Button link text from a website python selenium
  • Reverse string, but not integers
  • TkFiledialog.askopenfilename() launches a window for "save as" in windows 10
  • Printing last 3 lines of a .csv file
  • I can't install python packages by using pip3 on alpine
  • Setting up a Flask app that uses headed Selenium on a Ubuntu 18.04 LTS Server
  • How to convert month name to month number in a timeseries in DataFrame?
  • Why does pandas.where() returning 'None'
  • How to extract matching keywords from two columns in a pandas dataframe?
  • python converting a List of Tuples into a Dict with external keys
  • How to fix ModuleNotFoundError: No module named 'pip._internal' with python source code installation
  • Pytorch RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got CUDAType instead
  • Covert a dataframe into a matrix form
  • i am webscraping with bs4 and the urls wont show up
  • docker build: Returned a non-zero code: 5
  • Pandas read_csv from FileStorage in Flask
  • How do I add elements of a set and print their sum?
  • Is there a way to add a column to a geopandas dataframe using a single value geoseries?
  • Issue with appending to an array
  • no module named "tensorflow.python.platform" when importing tensorflow || tflearn on python shell
  • Accesing "Next" page with scrapy rules
  • How to take all combination of a pandas dataframe (choosing 2 at a time) and make a new dataframe with each two combinat
  • Connecting the missing pixels
  • Returns Nothing [] from Google + API using Python
  • pd.DataFrame: adding values in specific locations
  • Validating phone numbers in python using RE
  • How to fetch all data of solr which contains 40k rows into csv?
  • Inheritance of modules in Python?
  • ModuleNotFoundError: No module named 'frontend'
  • Only One Pod is consuming all the computing resource although specified the limits and requests resources in pod templat
  • IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
  • Scraping 'next' page after finishing in the main one using Rules
  • Add custom headers to SOAP request using zeep.Client Python
  • It the any proper way how to take a two byte elemetns from list, concat them, and convert them to integer
  • How to understand this simultaneous assignment evaluation in python 3?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk