2

I started working with python a couple of weeks ago and thus my knowledge of python is low.

I wish to plot a bar plot with some continuous data, but do not want to fill it with any color. I want to see only the final edges like a line histogram. I can not use white color because I will be overlapping different bar plots with errorbar plots in the same canvas. Any clue on how should I change it to a line histogram and set its line color?

For x-axis, I have used numpy.array. For y-axis, the height I need is in numpy.histogram form.

I am using following method:

import matplotlib.pyplot as plt

plt.bar(np_array_bins, np_histogram,width=binwidth,
        label='data', alpha=0.5, edgecolor = 'red', 
        color = 'green', linewidth=0.1)

I can't put the real data online but what I have is something like enter image description here

And I want : enter image description here

Neglect the data shown. I am concerned only about the style of the plot. Thanks!

4
  • Can you please provide images showing what you want vs what you have? Commented Jun 18, 2018 at 17:19
  • I have something like this: google.ch/…: And I want something like: google.ch/…: Only remove the fill color and have a colored line histogram... Commented Jun 18, 2018 at 17:23
  • Edit your question. Make sure you upload to a site that uses https. I'll fix the links to display correctly once you're done if you don't have sufficient rep. Commented Jun 18, 2018 at 17:26
  • Unrelated to answering the question: it's customary to import matplotlib.pyplot as plt. Commented Jun 18, 2018 at 17:36

4 Answers 4

3

From your description it sounds like you want a step plot or a histogram.

The step plot can be achieved with:

matplotlib.pyplot.step(np_array_bins, np_histogram, color="red", label="data")

enter image description here

The histogram can be achieved with:

matplotlib.pyplot.hist(values, histtype="step", edgecolor="red", label="data")

enter image description here

The important parameter here is histtype, setting it to step draws an unfilled line around the histogram. In this example your original array would be passed in and matplotlib would calculate the bin edges. You can define the bin edges yourself and set other parameters to get more control over the final plot, these are described in the matplotlib docs.

Sign up to request clarification or add additional context in comments.

Comments

0
import matplotlib.pyplot as plt

# Data for Ketchup stain removal
detergents = ['Tide', 'Ecos', 'Persil']
ratings = [5, 4, 3]

# Create the bar graph
plt.figure(figsize=(8, 6))
plt.bar(detergents, ratings, color=['blue', 'green', 'orange'])

# Adding labels and title
plt.xlabel('Laundry Detergents')
plt.ylabel('Stain Removal Rating (1-5)')
plt.title('Ketchup Stain Removal by Detergent')

# Display the graph
plt.ylim(0, 6)  # Set y-axis limit to make it visually clearer
plt.show()

2 Comments

Don't add code-only answers. Explain what your code does, why it works, and how it helps to solve the problem. Remember, answer should be useful for future visitors, even if they don't have the exact same code as the OP.
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
-1
import matplotlib.pyplot as plt

# Data

pod_lengths = [8.4, 7.0, 8.5, 8.8, 8.9, 6.7, 7.3, 7.9] number_of_seeds = [5, 5, 5, 5, 6, 4, 3, 5]

# Create a bar graph
plt.figure(figsize=(8, 5))
uplt.bar(pod_lengths, number_of_seeds, color='skyblue')

# Add labels and title
plt.xlabel('Pod Length (cm)')
plt.ylabel('Number of Seeds')
plt.title('Pod Length vs Number of Seeds')

# Show the plot
plt.show()

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
-1
import matplotlib.pyplot as plt

# Data

values_onion = [1, 9, 1, 5]

values_tipidtion = [5, 1, 5]

# Plotting

plt.figure(figsize=(10, 6))

plt.bar(['Onion-1', 'Onion-2', 'Onion-3', 'Onion-4'], values_onion, label='Onion')

plt.bar(['Tipidtion-1', 'Tipidtion-2', 'Tipidtion-3'], values_tipidtion, label='Tipidtion (Tip peeled)')

plt.xlabel('Plant Types')

plt.ylabel('Values')

plt.title('Plant Data Bar Chart')

plt.legend()

plt.show()

1 Comment

Don’t add code only answers. Explain what this code does why it works and how it helps to solve the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.