Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8764697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:05:57+00:00 2026-06-13T16:05:57+00:00

FINAL EDIT (Partial Solution): After a lot of tinkering I’ve been able to accomplish

  • 0

FINAL EDIT (Partial Solution):

After a lot of tinkering I’ve been able to accomplish what I want.
It isn’t exactly a fast bit of code as it’s plotting over 17,000 separate bar plots.

Solution

X = np.array(xvals)
Y = np.array(yvals)
Z = np.array(zvals)
Y_bot = np.array(bottomvals)

fig = plt.figure()
ax = fig.add_subplot(111)

jet = plt.get_cmap('jet')

log_norm = colors.LogNorm()

for x,y,z,bot in zip(X,Y,Z,Y_bot):
    log_z = np.log10(z)/np.log10(max(Z))
    colour = jet(log_price)
    ax.bar(x,y,bottom=bot, width=1, edgecolor='none',color=c_col)

a = np.vstack((Z,Z))
im = plt.imshow(a, aspect='auto', cmap=jet, origin='lower', norm=log_norm)
im.set_visible(False)
plt.colorbar(format='%.1f')
plt.axis([values])
plt.show()

This is able to successfully construct the plot I wanted, it automatically does the colour bar and formats it appropriately as well.

—- Begin Original Question —-

I am attempting to incorporate a logarithmic colour map to a series of stacked bar charts in matplotlib (python 2.7). Essentially, each “stack” value has a secondary value which I’m applying a logarithm transform to and then using that as part of a colour map.

There are two loops which run to create the plot:

import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.cm as cm
import matplotlib.colors as colors
import matplotlib.colorbar as cb
import matplotlib.ticker as tk    

for i in range(1,x):
    # get data for point i
    for n, j in enumerate(data):
        cval = log10(secondary value)
        plt.bar(i,j, bottom=sum(j[:n]), color=cm.jet(cval)

# Once it has all been plotted I want to set axis, titles and set up a color bar
# To set up the color bar I'm currently using

im = plt.imshow(a, aspect='auto',cmap=jet, origin='lower')
im.set_visible(False)
cbar = plt.colorbar()

Now, the issue is that these values are the log changed values (which is correct as that is what I’ve been using to plot the data).

But, I want to perform the reverse transform (e.g. 10 ** x) and have those valued displayed on the colorbar.

So far I’ve tried using:

cbar.ax.get_yticklabels() # This gets text values, not floats
cbar.ax.get_yticks() # This gets the positions

I know I can update the ticklabels using:

cbar.ax.set_yticklabels(new_ticks)

However, I want a generic way of obtaining the tick values in a way to make the transform.

The current format of the text values returned is:

Text(1,0,u'\u22121.6') # Corresponds to -1.6 in unicode (I think).

Any assistance would be greatly appreciated, this has been doing my head in.

In the end it should look something like this (Note, I’ve manually adjusted these tick values, axis labels have been removed as they’re not important)

enter image description here

EDIT:

I’ve also created a hexbin plot of the data, as you can see it is very very lumpy and generally messy to work with.

enter image description here

To generalise the above problem.

(notation, z =element, Z = vector array etc)

I have a data array Z with two unique indices (x, y).

I would like to plot each value of z at a location specified by its two indices (x, y). z should be coloured logarithmically. I would additionally like a colorbar to be plotted with this plot. Ideally, the spaces should be filled in, similar to the first stacked bar chart.

Note, X is an array of integers (although type is float) ranging from 1.0 to 48.0.
However, Y is an unconstrained float and no order links each value to X. Thus I’m unsure if contour plots are applicable here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:05:58+00:00Added an answer on June 13, 2026 at 4:05 pm

    After a lot of tinkering I’ve been able to accomplish what I want.
    It isn’t exactly a fast bit of code as it’s plotting over 17,000 separate bar plots.

    Solution

    X = np.array(xvals)
    Y = np.array(yvals)
    Z = np.array(zvals)
    Y_bot = np.array(bottomvals)
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    jet = plt.get_cmap('jet')
    
    log_norm = colors.LogNorm()
    
    for x,y,z,bot in zip(X,Y,Z,Y_bot):
        log_z = np.log10(z)/np.log10(max(Z))
        colour = jet(log_price)
        ax.bar(x,y,bottom=bot, width=1, edgecolor='none',color=c_col)
    
    a = np.vstack((Z,Z))
    im = plt.imshow(a, aspect='auto', cmap=jet, origin='lower', norm=log_norm)
    im.set_visible(False)
    plt.colorbar(format='%.1f')
    plt.axis([values])
    plt.show()
    

    This is able to successfully construct the plot I wanted, it automatically does the colour bar and formats it appropriately as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

FINAL EDIT: After following the answer from Darin Dimitrov, I have found that the
Final Edit: I was able to locate the duplicate field in the ini file.
read final edit for solution I'm try update the onclick function of a link
Final Edit : The wall of text below can be summed up by simply
FINAL EDIT: It does indeed appear to be a compiler bug - see the
Original I want to parse a string of html code and add newlines after
Final edit: Result using matplot() I'll see to it that I work with ~3
I want to be able to retrieve a users calendar and events from the
Final EDIT working code (Huge thanks to Claus for taking time and solving it):
FINAL EDIT (RESOLVED) I just replaced if(empty($num1)) with if(!isset($num1)) and now the conditional Required!

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.