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

  • SEARCH
  • Home
  • 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 6354719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:37:27+00:00 2026-05-24T22:37:27+00:00

I am trying to create some functions that will avoid me to repeat plot

  • 0

I am trying to create some functions that will avoid me to repeat plot options for different types of plot. I encounter some troubles as I try to create mechanisms to automatically handle Frameticks & Plot Range given the data considered within a given plot.

Module[{chartData},
        chartData = RandomInteger[20, 20];

BarChart[chartData,
                Frame -> {{True, True}, {True, True}},
                ImageSize -> 300,
                ChartStyle -> Black,
                FrameLabel -> {{"yName", None}, {None, "xName"}},
                ChartElementFunction -> "FadingRectangle",
                LabelStyle -> Directive[Black, Bold, 18],
                PlotRange -> {Automatic, 1.3*Max@chartData},
                FrameTicks -> {{{Round@Min@chartData, Round@(Max@chartData/2), 
                                Round@Max@chartData}, None}, 
                              {{0, Round@(Length@chartData/2), Length@chartData}, None}}
          ]]

enter image description here

Now Here is my attempt to simplify my life :

chartOptions[yName_, xName_] := {Frame -> {{True, True}, {True, True}},      
                                ImageSize -> 300,
                                ChartStyle -> Blue,
                                FrameLabel -> {{yName, None}, {None, xName}},
                                ChartElementFunction -> "FadingRectangle",
                                LabelStyle -> Directive[Black, Bold, 18],
                                FrameTicks -> {{{Round@Min@chartData, Round@(Max@chartData/2), 
                                                 Round@Max@chartData}, None}, 
                                              {{0,Round@(Length@chartData/2),     
                                               Length@chartData}, None}},
                                PlotRange -> {Automatic, 1.3*Max@chartData}}

This so that hopefully my actual Chart code is as such :

 Module[{chartData},
         chartData = RandomInteger[20, 20];

         BarChart[chartData,
         chartOptions["yName", "xName"]]]

But this does not work :

enter image description here

The idea is that the chartOptions function will be adjusted given the chart data of the actual plot where it is used.

I am now trying to only use things I trully understand so I hope such a problem does not require to much of your sophisticated skills 🙂 !

  • 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-05-24T22:37:28+00:00Added an answer on May 24, 2026 at 10:37 pm

    The problem is that in chartOptions the variable chartData is a free variable referring to a global definition. In the BarChart expression, the chartData variable is localized to the containing module and is thus invisible to chartOptions. Change chartOptions to accept chartData as a parameter:

    chartOptions[chartData_, yName_, xName] := ...
    

    and then adjust the BarChart expression accordingly:

    Module[{chartData},chartData=RandomInteger[20,20];
      BarChart[chartData,chartOptions[chartData, "yName","xName"]]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a function that will block access to some of
I'm trying to create a generic class which will have some static functions based
I'm trying to create a set of function templates that can take different types
My friend is trying to create a utility function that is given some Type
I am trying to create an form validator class that will check to make
I'm trying to create some HtmlHelper extensions and ran into a bit of a
I am trying to create some reusable components in Silverlight2 . The difficulty comes
I am trying to create some charts of data (eg http://www.amibroker.com/ ). Is there
I am trying to create some rules and facts on a certain situation. The
I am trying to create some global variables in a firefox extension. In my

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.