logo
down
shadow

matplotlib retrieve color from plt.plot command


matplotlib retrieve color from plt.plot command

By : user2956250
Date : November 22 2020, 10:54 AM
will be helpful for those in need The magic function you are searching is get_color(). However, the plot command returns a list with the lines objects and thus, you have to call this function on the items and not the list itself. Your function could look like
code :
import matplotlib.pyplot as plt
import numpy as np
def plotStuff():
    lines = plt.plot(np.random.rand(20))
    color = lines[0].get_color()
    plt.plot(np.random.rand(20),color = color,label = "_nolegend_" )
plotStuff()


Share : facebook icon twitter icon
How can I print a plot in matplotlib either from the plot window or with a command?

How can I print a plot in matplotlib either from the plot window or with a command?


By : user3531932
Date : March 29 2020, 07:55 AM
should help you out You could save the figure as a pdf, then use subprocess to print the pdf. On *nix, lpr could be used:
code :
import matplotlib.pyplot as plt
import numpy as np
import subprocess
import shlex

n=20
x=np.linspace(0,np.pi,n)
y=np.sin(x)
plt.plot(x,y)
fname='/tmp/test.pdf'
plt.savefig(fname)
proc=subprocess.Popen(shlex.split('lpr {f}'.format(f=fname)))
Define plot label outside plt.plot() command - Matplotlib

Define plot label outside plt.plot() command - Matplotlib


By : Brian Hillegeist
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I'm making a scatter plot that uses two different symbols based on a condition in the data. In a for loop iterating through the rows of the data, if a condition is met a point is plotted with a circle, and if not met the point is plotted with a square: , This is the pattern I use in such cases:
code :
label_o = 'Circle'
label_s = 'Square'
for i in thick.index:
    if thick['Interest'][i] == 1:
        plt.scatter(thick['NiThickness'][i], thick['GdThickness'][i], marker=o', color='b', label=label_o)
        label_o = None
    else:
        plt.scatter(thick['NiThickness'][i], thick['GdThickness'][i], marker='s', color='r', label=label_s)
        label_s = None
matplotlib: How to plot multiple scatter plots in one grid where each plot is different color based on a separate list?

matplotlib: How to plot multiple scatter plots in one grid where each plot is different color based on a separate list?


By : user3409679
Date : March 29 2020, 07:55 AM
With these it helps I am currently plotting the color values of images per pixel, I am trying to create a plot for each image. I have around 100 images. I want all plots to be present in a single grid but I still want to track what image the plot represents. , Here is a minimum working example of what you might be trying to do:
code :
import pylab as pl

pl.clf()
for count in range(5):
    pl.scatter(pl.rand(10), pl.rand(10), color=pl.cm.seismic(count / 5.0), s=50)
Change 1 point color in scatter plot regardless of color palette in seaborn matplotlib

Change 1 point color in scatter plot regardless of color palette in seaborn matplotlib


By : Jonathan Wermut
Date : March 29 2020, 07:55 AM
wish of those help You can replace one color in the palette by converting it to a list of colors and then replace one of the colors by some other color of your liking.
code :
import pandas as pd
import numpy as np;np.random.seed(42)
import matplotlib.pyplot as plt
import seaborn as sns

letters = list(map(chr, range(ord('A'), ord('Z')+1)))
df = pd.DataFrame({"NAME" : letters, 
                   "VALUE": np.sort(np.random.rand(len(letters)))[::-1],
                   "ID" : ["X"]*len(letters)})

special_letter = "B"
special_color = "indigo"

levels = df["NAME"].unique()
colors = sns.color_palette("hls", len(levels))
inx = list(levels).index(special_letter)
colors[inx] = special_color

ax = sns.stripplot(x="ID", y="VALUE", hue="NAME", data=df, 
                     jitter=True,  s=7, palette=colors)

ax.legend(ncol=3, bbox_to_anchor=(1.05,1), loc=2)
ax.figure.subplots_adjust(right=0.6)
plt.show()
levels = df["NAME"].unique()
colors = sns.color_palette("hls", len(levels))
colors = dict(zip(levels, colors))
colors[special_letter] = special_color
Matplotlib Quiver plot matching key label color with arrow color

Matplotlib Quiver plot matching key label color with arrow color


By : priyanka
Date : March 29 2020, 07:55 AM
will help you Supposedly you meant to be using the color argument of quiver to set the actual colors.
code :
import matplotlib.pyplot as plt

q=plt.quiver([1, 2,], [1, 1], [5,0], [5,5],
             color=[(0.6, 0.8, 0.5, 1.0 ), (0.3, 0.1, 0.2, 1.0 )])
plt.quiverkey(q, .5, .5, 7, r'vector2', labelcolor=(0.3, 0.1, .2, 1),
                      labelpos='S', coordinates = 'figure')

plt.show()
q=plt.quiver([1, 2,], [1, 1], [5,0], [5,5],
             [(0.6, 0.8, 0.5, 1.0 ), (0.3, 0.1, 0.2, 1.0 )])
q=plt.quiver([1, 2,], [1, 1], [5,0], [5,5],
             [0.6, 0.8], norm=plt.Normalize(vmin=0.1, vmax=1))
Related Posts Related Posts :
  • ModuleNotFoundError: No module named 'users'
  • Interpolating with multiple y-values
  • Import warning PACKAGE.egg is added to sys.path
  • Is there a key for the default namespace when creating dictionary for use with xml.etree.ElementTree.findall() in Python
  • Using fill_between() with a Pandas Data Series
  • How to build a lookup table for tri-linear interpolation in NumPy?
  • Matrix vector multiplication along array axes
  • Can a cookiejar object be pickled?
  • __init__.py in project folder breaks nose tests
  • Comparing times with sub-second accuracy
  • advanced search using HayStack + Solr in Django?
  • Base test case class for python unittest
  • The PyData Ecosystem
  • Finding unique entries with oldest time stamp
  • Custom filesize format with Python Humanize?
  • Use `tf.image.resize_image_with_crop_or_pad` to resize numpy array
  • Sum number of occurences of string per row
  • Calculating 'Diagonal Distance' in 3 dimensions for A* path-finding heuristic
  • porting PyGST app to GStreamer1.0 + PyGI
  • Connection refused in Tornado test
  • How much time does take train SVM classifier?
  • Turning a string into list of positive and negative numbers
  • Python lists get specific length of elements from index
  • python.exe version 3.3.2 64 & 32 crash while creating .exe file on win 7 64 & 32 with cx_Freeze
  • Efficient nearest neighbour search for sparse matrices
  • django filter_horizontal can't display
  • How to install FLANN and pyflann on Windows
  • How can I plot the same figure standalone and in a subplot in Matplotlib?
  • read-only cells in ipython notebook
  • filling text file with dates
  • error:AttributeError: 'super' object has no attribute 'db_type' when run "python manage.py syncdb" in django
  • python imblearn make_pipeline TypeError: Last step of Pipeline should implement fit
  • Write to csv: columns are shifted when item in row is empty (Python)
  • DuckDuckGo search returns 'List Index out of range'
  • Python function which can transverse a nested list and print out each element
  • Python installing xlwt module error
  • Python mayavi: Adding points to a 3d scatter plot
  • Making a basic web scraper in Python with only built in libraries - Python
  • How to calculate the angle of the sun above the horizon using pyEphem
  • Fix newlines when writing UTF-8 to Text file in python
  • How to convert backward slash command in python to run on Linux
  • PyCharm Code Inspection doesn't include PEP 8
  • How can I use Python namedtuples to insert rows into mySQL database
  • Increase / Decrease Mac Address in Python from String
  • Scrollable QLabel image in PyQt5
  • (Python 2.7) Access variable from class with accessor/mutator
  • Why does "from [Module] import [Something]" takes more time than "import [Module"
  • jira python oauth: how to get the parameters for authentication?
  • Python - How to specify a relative path by jumping a subdirectory?
  • Extract scientific number from string
  • Scrapy: Python cannot find the spider
  • get the values in a given radius from numpy array
  • Is it possible to duplicate a pipe in Python, so that it has one write end but two read ends?
  • Why does wget use Firefox cookies to login on an authenticated webpage?
  • python import behaviour: different objects from same file?
  • Create YoY Graph with Matplotlib
  • Safe use of eval() or alternatives - python
  • Unix change desktop background seamlessly
  • Profiling Python code that uses multiprocessing?
  • How to query a database after render_template
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org