How to plot a line of a certain color?

1.929 Ansichten (letzte 30 Tage)
Hail
Hail am 15 Aug. 2014
Verschoben: Image Analyst am 6 Mär. 2023
I have 7 lines on a single plot. I dont want to use the 'y' color code. How can I make my own color? I also want this line to have asterisks along it. So currently I have 'y*-' but again I dont want to use yellow

Akzeptierte Antwort

Chad Greene
Chad Greene am 15 Aug. 2014
plot(x,y,'*','color','blue') plots in blue. plot(x,y,'*','color',[.5 .4 .7]) plots the RGB value [.5 .4 .7]. If you want lots of color names, you could use the rgb function to return the RGB values of just about any color. For example, plot(x,y,'*','color',rgb('blood red'))
  1 Kommentar
MathWorks Support Team
MathWorks Support Team am 3 Sep. 2020
Starting in R2019a, you can also specify colors using hexadecimal color codes such as #0076a8. For example, plot(x,y,'*','Color','#0076a8') plots asterisks using a custom shade of blue.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Image Analyst
Image Analyst am 15 Aug. 2014
Of course Chad's answer is best . But I just thought I'd show people how to change the default color order that you get when you plot lines without specifying the color. Ever wonder how it plots blue first, then dark green, then red, then cyan, etc.? Ever want to change the default order so that it plots curves with the color order you want instead of the default color order, and without having to specify the color in every single call to plot()? If so, run the attached demo.
  1 Kommentar
MathWorks Support Team
MathWorks Support Team am 3 Sep. 2020
Starting in R2019b there is a new colororder command that you can use to change the colors of new and existing lines. This command takes RGB colors, color names, and hexadecimal color codes as input. For additional details about managing the colors and line styles in plots, see Control Colors, Line Styles, and Markers in Plots in the MATLAB documentation.

Melden Sie sich an, um zu kommentieren.


David
David am 6 Mär. 2023
Verschoben: Image Analyst am 6 Mär. 2023
To plot a line of a certain color in a graph or chart, you can use the color parameter in the plotting function of your programming language. Here's an example of how to do it in Python using the Matplotlib library:
import matplotlib.pyplot as plt
# Generate some data to plot
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
# Plot the line with a specific color
plt.plot(x, y, colors='red')
# Add axis labels and a title
plt.xlabel('X-axis label')
plt.ylabel('Y-axis label')
plt.title('Plot with a red line')
# Show the plot
plt.show()
In this example, the plot function is used to plot the data points, and the color parameter is set to 'red' to change the color of the line to red. You can replace 'red' with any other valid color name or hexadecimal color code to change the line color to your desired color.

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by